I think another table is needed. I don't have any inspiration right now for the name, lets call it X. :D
Then
A student has many X,
A X belongs to a course,
A X has and belongs to many mandatories.
This way :
foreach($student->x as $x){
foreach($x->mandatories as $mandatory){
echo $x->course->name . ' - ' . $mandatory->name;
}
}
Then you can remove students/courses M2M relationship and replace it by a has many through relationship (through X)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community