You can use "hasManyThrough" for this. Check the documentation here: https://laravel.com/docs/5.5/eloquent-relationships#has-many-through
Nov 17, 2017
3
Level 2
Find all the examinations taken by a lecturer ?
Ok. I have three database:
examination. pk id lecturers. pk id exam_supervision: fk lecturer_id and exam_id
I want to join these tables to find all exam taken by the lecturer.
So if I implement hasMany method in examination and lecturer model:
examination model class:
public function supervised()
{
return $this->hasMany('exam_supervision');
}
lecturer model class:
public function supervises()
{
return $this->hasMany('exam_supervision');
}
then should I do this?
$examinationByLecturer = Exam_supervision::with('examination','lecturers, )->get();
I am confused about laravel syntax. Very confusion
Please or to participate in this conversation.