0

I have 3 Models that are related so : "Tutorial" belongs To "Title" that belongs to "Course". Or (the other way) . A "Course" has many "Titles" that have many "Tutorials" . And I want to find a course based on its id and grab all its titles and tutorials using the eager loading . the code looks so :

$course = Course::with('titles')->where('id','=',$id)->get(); 

// this returns only a Course with its titles , but I want to get also tutorials that belongs to each title.

arakibi
  • 441
  • 7
  • 24

1 Answers1

2

You can eager load nested relations with the dot-syntax as documented here

$course = Course::with('titles.tutorials')->find($id);

As you can see I also changed the where('id', '=', $id) to find($id). This will do the same but also only return one result instead of a collection.

lukasgeiter
  • 147,337
  • 26
  • 332
  • 270