Dynamically create x-media-library-collection component
#3692
Unanswered
Rexy-Gamaliel
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
laravel-medialibrary-prov2.7.3 andlivewirev2.12.8 to make a form page for a content management system. I have 2 Laravel models:PartnerandPartnerDocumentin a one-to-many relationship. ThePartnerDocumentmodel contains some additional data for the file that is associated with it, so this model uses theSpatie\MediaLibraryPro\Http\Livewire\Concerns\WithMediatrait.I've tried the example here and wondered how to apply it in a situation where the
x-media-library-collectionhas to be created dynamically. My idea was to use an "Add" button that does the following:MyFormclass:1.1. generate a random unique string
$key, append it to$this->keysarray1.2. create custom properties:
$this->{'partner_document_' . $key}of typePartnerDocumentand$this->{'media_' . $key}1.3. add
'media_' . $keyto$this->mediaComponentNamesMyForm's component blade template:Lastly, when the submit button is clicked, it calls
savemethod as such:But the uploaded file cannot be associated with the model. On the
mediatable, it is associated withSpatie\MediaLibraryPro\Models\TemporaryUploadbut notPartnerDocument. The property$this->$mediais always an empty array.I've been trying to make it work for quite a while but can't seem to find a solution. Any help is greatly appreciated, thank you!
Beta Was this translation helpful? Give feedback.
All reactions