F
Filament11mo ago
Gush

FileUpload String saved

Forms\Components\FileUpload::make('thumbnail')
->label('image')
->acceptedFileTypes(['image/*'])
->directory('opportunity_images')
->storeFileNamesIn('original_filename'),
Forms\Components\FileUpload::make('thumbnail')
->label('image')
->acceptedFileTypes(['image/*'])
->directory('opportunity_images')
->storeFileNamesIn('original_filename'),
how do i save the image string without it saving as "opportunity_images/ ... "
Solution:
Can you remove the prefix when you are getting the value from the database? Does it impact other parts of the app to have the prefix in the DB?
Jump to solution
12 Replies
Gush
Gush11mo ago
it goes to the right folder but stores the path to database
Solution
Patrick Boivin
Patrick Boivin11mo ago
Can you remove the prefix when you are getting the value from the database? Does it impact other parts of the app to have the prefix in the DB?
Gush
Gush11mo ago
yes because i get the image like this
src="{{ url('storage/opportunity_images/' . $getRecord()->thumbnail) }}
src="{{ url('storage/opportunity_images/' . $getRecord()->thumbnail) }}
Mark Chaney
Mark Chaney11mo ago
im confused. you marked this as already solved, but is it?
Gush
Gush11mo ago
no, i didnt mean to
Mark Chaney
Mark Chaney11mo ago
@Gush why would you not simply get images as src="{{ url('storage/' . $getRecord()->thumbnail) }}?
Gush
Gush11mo ago
organization
Mark Chaney
Mark Chaney11mo ago
@Gush my point is that its already part of the filename that is stored
Patrick Boivin
Patrick Boivin11mo ago
Yeah, I don't understand what's more organized about removing the prefix from the DB? If the file is really in a folder on the disk, you'll need to add the prefix to the path sooner or later, or am I missing something?
cheesegrits
cheesegrits11mo ago
My advice would be don't fight the system. Pretty much every form / app building kit I've ever used in any framework stores the relative path from the content / virtual disk root when uploading files. Trying to buck that means overriding default behavior, and potentially introducing more problems in the future if there is other code internally that assumes how the path is built. Just go with the conventions. Same as any convention in Laravel. Sure, you can do it some other way, but you're just making extra work for yourself.
Gush
Gush11mo ago
"This question is already marked as solved" ⬆️ somebody mark Hugh answer as solution pls
trovster
trovster11mo ago
I had the same issue. I do not want the folder path in the database column, as I model this. I was using an Action so I was able to manipulate the column and remove the path before the action saved the model.