How do I persist FileUpload's result?

I realize this is a simple question but I cannot find the answer. I've got a resource's Form with a FileUpload input. I've read the documentation but I can't for the life of me find any information about where/how to persist information about the upload to the database. I've already got a File model (which is the model that the resource's form is connected to) but don't know where to put any code in FileResource to handle the upload. Thank you!
7 Replies
awcodes
awcodes12mo ago
It’s handled automatically unless you need to override how it it saved.
gmgarrison
gmgarrisonOP12mo ago
Is there documentation for the fields it saves and what column names it expects? I guess I understand that the fields created in the form correspond to columns in the model. But there are attributes for the file that are derived from the actual upload - original filename, size, path. How can they be persisted? (Follow up question which I realize is more ocmplicated... if I have a generic File table that stores any uploaded file and a different Resource table that stores every resource, only some of which are uploaded files, how do I set up the form in Resource to have a FileUpload input that creates a File and then stores the file_id in Resource?)
awcodes
awcodes12mo ago
If you need all of that information you would need to have a separate table and model for media and use a relationship. Or you could use Filaments spatie media library plugin, or something like #media-library-pro or #curator
gmgarrison
gmgarrisonOP12mo ago
I thought I did have a separate table for the media - it's File. But it sounds like what you're telling me is that there's no mechanism for custom behavior in the resource form saving/upload process? There's no exposed place in the Filmament lifecycle where I could write custom behavior while still having the $_FILES object (totally great if there's a Filament wrapper around it) still accessible? I'll admit I haven't played around with the upload-related plugins yet. I'll spend some time with those today.
awcodes
awcodes12mo ago
->saveUploadedFileUsing()
awcodes
awcodes12mo ago
GitHub
filament-curator/src/Components/Forms/Uploader.php at 3.x · awcodes...
A media picker plugin for Filament Panels. Contribute to awcodes/filament-curator development by creating an account on GitHub.
gmgarrison
gmgarrisonOP12mo ago
Hmmm... interesting!! Thank you!
Want results from more Discord servers?
Add your server