I have a form with a field named "cover" and that form is for a Demo model that have a Media Collection we can access like this
$demo->getMedia('cover').
When I open if I do json_encode($demo->getMedia('cover')) it calls jsonSerialize() from Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection
This works but if I have some field missing and the cover input have any value the the json_encode($demo->getMedia('cover')) will crash, because the jsonSerialize() method is like this
In this case this method will return what is inside old('cover') in my case this is a string with the name of the file and a string is not an array and I get an error.
I this this code should be improved to prevent to return something that is not an array where this is my suggestion:
I have a form with a field named "cover" and that form is for a Demo model that have a Media Collection we can access like this $demo->getMedia('cover').
When I open if I do json_encode($demo->getMedia('cover')) it calls jsonSerialize() from Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection
This works but if I have some field missing and the cover input have any value the the json_encode($demo->getMedia('cover')) will crash, because the jsonSerialize() method is like this
In this case this method will return what is inside old('cover') in my case this is a string with the name of the file and a string is not an array and I get an error. I this this code should be improved to prevent to return something that is not an array where this is my suggestion: