Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

perara perara Joined 1 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.