Search code examples
laraveleloquenteager-loading

Laravel Eloquent: eager loading of multiple nested relationships


What laravel says:

$books = App\Book::with('author.contacts')->get();

What I need is something like this

$books = App\Book::with('author[contacts,publishers]')->get();

where we eager load multiple relationships within a relationship.

Is this possible?


Solution

  • You can do

     $books = App\Book::with('author.contacts','author.publishers')->get();