Laravel-medialibrary: Media collection always empty

Created on 12 Apr 2018  路  3Comments  路  Source: spatie/laravel-medialibrary

I have media results stored in the database with the correct information, model, id etc... But when I try to query the media to pull results my collection is always empty;

$page = Page::where('slug', $p)->firstOrFail();
$media = $page->getMedia();
dd($media);

When I use $media = $page->Media(); the media collection is empty.

Most helpful comment

Thank you for posting your solution. I was about to tear my hair out trying to figure out why this wasn't working. The docs should definitely address this if they don't already (I didn't see this noted anywhere)

All 3 comments

Issue resolved you have to pass a collection name to getMedia(); if you're not using the "default" collection. in my instance getmedia('banner');

Thank you for posting your solution. I was about to tear my hair out trying to figure out why this wasn't working. The docs should definitely address this if they don't already (I didn't see this noted anywhere)

Yes, I also don't see it in the documentation, worth updating to accommodate. Well done on resolving your issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drtheuns picture drtheuns  路  3Comments

kickthemooon picture kickthemooon  路  4Comments

eichgi picture eichgi  路  3Comments

swash13 picture swash13  路  3Comments

intrepidws picture intrepidws  路  3Comments