FileUpload store path instead of filename
Hello everyoone. Just moved to Filament from previous legacy admin panel. I really need FileUpload to store relative path instead of just a filename for compatibility reasons. Is it possible to achieve with hooks like before and after hydration?
Solution:Jump to solution
I was able to achieve this by extending FileUpload class
```
namespace App\Forms\Components;
class FileUpload extends BaseFileUpload...
11 Replies
Can you elaborate more?
In worst case scenario you can create separate field eg.
path_relative
and build its state to match your requirement.
Take look https://filamentphp.com/docs/3.x/forms/fields/file-upload#generating-custom-file-names Maybe this will solve your case.
Edit: fixed linkLet's say i have field called image. Its value is stored in database as 'uploads/somefile.jpg'. FileUpload expects its value to be 'somefile.jpg' in order to work correctly. So i need somehow to alter its value and remove 'uploads/' before it goes to FileUpload, then i need to add it back before it goes to database.
filament uses Laravel storage, so assuming you use 'public' disk, you can go with:
https://filamentphp.com/docs/3.x/forms/fields/file-upload#configuring-the-storage-disk-and-directory
Then, field will expect the value to be
uploads/someFile.jpg
not someFile.jpg
and will store it properly too.nah, i configured uploads disk, i need path to contain disk's directory
if above is not the way,
afterStateUpdated
and dehydrateStateUsing
are your friends 😉i need something like this, but i'm not sure if it is possible with FIleUpload field
for me it looks like it should be working.
It works with TextInput, but gives errors with FileUpload, even if i do no processing at all
Solution
I was able to achieve this by extending FileUpload class