laravel-medialibrary: Returning files with Eloquent collection

If I’m returning many rows from a database, I don’t see how to getMedia for each row.

$movies = MovieList::orderBy('sort_title', 'asc', 'release_year', 'asc') ->get(); $posterFiles = $movies->getMedia();

Doing the above returns the error “Method getMedia does not exist”.

I can’t find how to do this in the documentation.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

👍

Providing a description of the problem and your solution here might help future users who might have the same problem.

I had this problem and i had to solve it like this

 $article = Article::all();
 foreach ($article as $k => $v) {
       $article[$k]->getMedia();
 }

it should work with any collection of models