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
Dan Harrin
Dan Harrin2y ago
the reason why its happening is because of the directory() by default, we will use the public directory
Filament
Filament2y ago
Filament
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.
Dan Harrin
Dan Harrin2y ago
instead of using ->disk('local')->directory('public'), your app is probably not set up correctly. see the link above
Shubham chugh
Shubham chughOP2y ago
@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.
Want results from more Discord servers?
Add your server