Laravel / Eloquent query between unrelated tables (Many to many)

3

My problem is that I have a many to many relationship between the subject and teacher table, therefore, I have a detail or intermediate table ( teacherSubject ).

I must show in Teacher the subject blade teacher that they are related to that teacher , how they see I can not use join because directly the subject and teacher tables are not related since the IDs are retrieved in the detail table.

I tried to use the intermediate table for that purpose but I do not have a specific idea of what to call the attribute.

How could I do it?

    
asked by Kibō_B 14.06.2018 в 00:08
source

1 answer

1

In model subject

 public function teachers()
    {
        return $this->belongsToMany('App\Teacher','teacherSubject ','id_subject','id_teacher');
    } 

In model teacher

public function subjects()
    {
        return $this->belongsToMany('App\Subject','teacherSubject ','id_subject','id_teacher');
    }
    
answered by 14.06.2018 в 17:02