O'Reilly logo
  • GIL EG thinks this is interesting:

 $books = \App\Book::with('author', 'categories')->take(100)->get();

  foreach($books as $book)
  {
    $author = $book->author;

    echo 'Author: ' . $author->first_name . ' ' . $author->last_name;

    echo 'Categories:';

    foreach($book->categories as $category)
    {
      echo $category->name . ', ';
    }
  

From

Cover of Learning Laravel's Eloquent

Note

multiple related models in Eager loading