Spatie Media Library File upload - for each file, create model record

Hello everyone, I want every upload to be a different record. I though of editing the CreateAction and when I'm uploading loop through the files ($data) and create one record for each. Problem is: using SpatieMediaLibraryFileUpload, the files don't go through the array $data, so I can't loop through them. I'm not sure if I'm being clear, but I wonder if you can help? In the screenshot I uploaded 5 files, but the $data array only returns the description.
No description
6 Replies
awcodes
awcodes15mo ago
With spatie’s package each file is it’s own record. It’s handle through a relationship.
Diogo Pinto
Diogo PintoOP15mo ago
I understand that, and makes sense. But what I'm trying to achieve is: - Each user has lots of documents and each document has multiple options -- you can set descriptions, expiration date, set it to public or private, etc So I thought of creating a Model (UserDocuments) that implements the SpatieMediaLibrary, but has its own logic. You don't think this is good approach? I thought of using CustomProperties, but an isolated Model seemed more efficient
awcodes
awcodes15mo ago
There’s already a relationship between the user and the media. So you can just get it from the user record. Look at the spatie docs to see how to do that.
Diogo Pinto
Diogo PintoOP15mo ago
Thank you @awcodes, I will look deeper at the docs!
awcodes
awcodes15mo ago
make sure you look at the docs for the Spatie Media Library and not the Filament docs. 🙂
Diogo Pinto
Diogo PintoOP15mo ago
Got it! Thanks again for your help
Want results from more Discord servers?
Add your server