samedi 30 novembre 2019

Laravel 5 : Is there any way to chain many to many relation with one to many relation?

I have three tables in my database : 1) Teacher 2) Course 3) Timetable

Teacher and Course tables are connected through many to many relationship as each teacher can teach many courses and each course can have many teachers:

-----------------          ------------------------         ----------------      
     Teacher                   CourseTeacher                    Course
-----------------          -------------------------        ----------------
id         name            id  course_id   teacher_id        id       name
1          John             1    1            1              1       English

Teacher -> ManyToMany -> Course

Now foreach course , a teacher can have a many days with time on which he teaches that specific course,so there would be another table named timetable which has the following structure:

---------------------------------------------------
                     TimeTable
----------------------------------------------------
id    day         time       teacher_id    course_id
1     monday      10:00 pm     1              1
2     tuesday     10:00 pm     1              1

Now the question is how can i connect the timetable table with CourseStudent relation through one to many relationship . For each teacher teaching the course i need to save the timetable of teacher for that specific course .

Teacher -> ManyToMany -> Course
          |
          |
     One to Many
          |
      TimeTable


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire