Request for a solution to store only the uploaded image name in the database using Filament
Hello,
I am using the FileUpload class in Filament to handle site logo file uploads on my website. I have the following code:
FileUpload::make('site_logo')
->label('Site Logo')
->disk('local')
->directory('public')
->maxSize(2000)
->enableDownload()
->getUploadedFileNameForStorageUsing(function (): string {
return (string) str('logo.png');
})
->columnSpan('full')
->image();
This code stores the uploaded image with the 'public' directory included, so it is saved as 'public/logo.png' in the database. However, I only want to store the filename 'logo.png' in the database.
When I remove the ->disk('local')->directory('public') lines of code, it stores only the filename 'logo.png', but the preview does not display.
Do you have a solution to store only the filename of the uploaded image in the database while still displaying the preview correctly?
Thank you.
4 Replies
the reason why its happening is because of the
directory()
by default, we will use the public directoryFilament
File upload previews not loading by Dan Harrin - Tricks - Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
instead of using
->disk('local')->directory('public')
, your app is probably not set up correctly. see the link above@Dan Harrin Thanks, it's working fine now. It was my mistake as I recently switched from Sail to Laradock and forgot to update the APP_URL.