I am trying to load a nested realtionship from a model that can have or not a "main" relationship.
I have 3 models: Building, Address and City.
I have a Building model that optionally can have an Address relationship.
If the Address relationship exists it always have a City relationship itself.
My "list buildings" controller function looks as follow:
$buildingList = Building::with(['address','type'])->get();
The problem is this way the City nested relationship isn't loaded, so I did try the following:
$buildingList = Building::with(['address.city','type'])->get();
This way I get an error for every Building that hasn't an Address related model.
Is there an elegant way to solve this?
city
on Adress model?