SpatieMediaLibraryFileUpload not showing
I'm using Form Builder in a Livewire normal component.
I have this field:
firstly, when I do submit I save the media like this:
At that point, media is saved successfully in the database, and attached correctly to the model.
When I refresh the page, the Spatie field looks like empty.
I have tried to add
but no changes are.
Any thought?
13 Replies
How are you gettin the data? it should be with form->getState() for it to process the images correctly. You shouldn't need to manually add the media etc
hm, doing form->getState() it doesn't appear the media input attribute🤔
by doing that it handles it behind the scenes and shouldn't need to to do anything
it doesn't work at all...
doing a dd() of form state the 'main_image' attribute it doesn't appear and it's not saving neither
I found the trick. I was not assigning the form model...
That'll do it!
Is there any trick to assign it dynamically? For example to use the same form with different models
So the model shouldn't need assigning looking at it. have you applied the has media to the model?
The model you are saving the form data too, should implements HasMedia and use InteractsWithMedia
That should be enough for the field to assign it to that model.
I have this use case
Oh ok interesting
I am unsure quite how to handle that
I assume you are assigning the model with ->model() ? if so, can you pass the model in when calling the edit function?
I tried this:
$this->form->model($this->model) but not working 😦 is passing all fields except media
And each model you are trying to save the image against implements HasMedia and use InteractsWithMedia
yes