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-pro
v2.7.3 andlivewire
v2.12.8 to make a form page for a content management system. I have 2 Laravel models:Partner
andPartnerDocument
in a one-to-many relationship. ThePartnerDocument
model contains some additional data for the file that is associated with it, so this model uses theSpatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia
trait.I've tried the example here and wondered how to apply it in a situation where the
x-media-library-collection
has to be created dynamically. My idea was to use an "Add" button that does the following:MyForm
class:1.1. generate a random unique string
$key
, append it to$this->keys
array1.2. create custom properties:
$this->{'partner_document_' . $key}
of typePartnerDocument
and$this->{'media_' . $key}
1.3. add
'media_' . $key
to$this->mediaComponentNames
MyForm
's component blade template:Lastly, when the submit button is clicked, it calls
save
method as such:But the uploaded file cannot be associated with the model. On the
media
table, it is associated withSpatie\MediaLibraryPro\Models\TemporaryUpload
but notPartnerDocument
. The property$this->$media
is 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