Multiple loading in Laravel?

Say I have this relationship

class Invitation { public function invitedPeople() { return $this->belongsTo('App\Person', 'personID'); } } class Person { public function apartments() { return $this->belongsToMany('App\Apartment', 'apartment_person', 'personID', 'apartmentID'); } } class Apartment { public function city() { return $this->belongsTo('App\City', 'cityID'); } } 

My question here is how many nested levels do we have when using Laravel with impatience? I tried this request and it does not work, can anyone suggest a job for this?

 return Invitation::with(['invitedPeople', 'invitedPeople.apartments', 'invitedPeople.apartments.city']) 
+6
source share
1 answer

Change it to

  return Invitation::with('invitedPeople.apartments.city')->get() 

It will download all related data for you. You missed the get () function. You can nest as deep as possible.

+7
source

All Articles