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

$categories = \App\Categories::with('books.author')->get(); foreach($categories as $category) { echo $category->name; foreach($category->books as $book) { echo 'Title: ' . $book->title; echo 'Author: ' . $book->author->first_name . ' ' . $book->author->last_name; } }

From

Cover of Learning Laravel's Eloquent

Note

nested relationship with Eager loading (loading the related of related models)