F
Filament16mo 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
GushOP16mo ago
it goes to the right folder but stores the path to database
Solution
Patrick Boivin
Patrick Boivin16mo 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
GushOP16mo 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 Chaney16mo ago
im confused. you marked this as already solved, but is it?
Gush
GushOP16mo ago
no, i didnt mean to
Mark Chaney
Mark Chaney16mo ago
@Gush why would you not simply get images as src="{{ url('storage/' . $getRecord()->thumbnail) }}?
Gush
GushOP16mo ago
organization
Mark Chaney
Mark Chaney16mo ago
@Gush my point is that its already part of the filename that is stored
Patrick Boivin
Patrick Boivin16mo 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
cheesegrits16mo 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
GushOP16mo ago
"This question is already marked as solved" ⬆️ somebody mark Hugh answer as solution pls
trovster
trovster16mo 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.
Want results from more Discord servers?
Add your server