Laravel: how to load a model that is two steps down?

Say I have users who have many computers belonging to a particular computer_type (users-> computers-> computer_type).

I know that I can load both users and their computers with: User::with("Computer")

I would like to download all three. How can I do this in Laravel?

+7
source share
2 answers

To get a relationship that is far down, you must say that this is a child, then a child with him, etc.

 User::with(array('computer', 'computer.type'))->find(1); 

User has_one In this particular scenario, the computer has its own type.

+16
source

Try

 Appointment::with('kid.parent')->get() 

if each child has an appointment and each child has a parent.

+1
source

All Articles