Replies: 2 comments
-
Related pull request: #3210 |
Beta Was this translation helpful? Give feedback.
-
thanks for this. puzzled why the collection always returned empty in json while the items where there.. figured it would be something like this.. personally I share your opinion to follow the standard Laravel things. its just easier to work, especially on larger projects. Seems like your pull request is still to be merged; sadly without a ETA big thanks @BARNZ !! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the Media model directly to manually filter and query media from the database and return results from route/controller, the following code worked fine in v8:
In v9 and v10 this is broken - it now always returns an empty array
[]
.Looking into things, the following appears to be the culprit:
laravel-medialibrary/src/MediaCollections/Models/Collections/MediaCollection.php
Line 57 in 2d18551
Media:all()
now returns a MediaCollection which has its ownjsonSerialize
which always returns an empty array for the above scenario. I dont quite understand the purpose of this custom MediaCollection, but I would expect Media collections to serialize the same as any other laravel model collection.My workaround for now is on my custom media model add the following override to prevent
MediaCollection
being used:Perhaps a fix for this use-case can be added, or maybe something that needs adding to the upgrade guide?
Quite often there is a need to chain some additional filters off a media builder then return the filtered media directly from a controller as a json array - so I would have thought this would be quite a common scenario. From what I can tell I cant see anyone else having logged this issue.
Beta Was this translation helpful? Give feedback.
All reactions