You can use something like this
School::with('teachers','teachers.pupils')->get();
Just adust the names of your relationships
pixelpeter said:
You can use something like this
School::with('teachers','teachers.pupils')->get();
Just adust the names of your relationships
That will eager load pupils but not combine them.
I think the only way for now could be something like this:
Pupil::whereIn('teacher_id', function($query) use ($school) {
$query->select('id')->from('teachers')->where('school_id', $school->id);
});
cheers popolla your suggestion worked!
maybe pushing it here but is there any way to add in another level?!
something like area->school->teachers->pupil ?
thanks again.
by the way for anyone looking in I had to add ->get() onto the end of popolla's query otherwise there was a recursion error
lainga9 said:
maybe pushing it here but is there any way to add in another level?!
something like area->school->teachers->pupil ?
Try this one:
$pupils = Pupil::whereIn('teacher_id', function($query) use ($area) {
$query->select('teachers.id')->from('teachers')
->join('schools', 'teachers.school_id', '=', 'schools.id')
->where('schools.area_id', '=', $area->id);
})->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community