query with many-to-many polymorphic laravel?

0

I have a polymorphic m-m relationship in my bank where:

  

class (id, name)

     

student (id, name)

     

lesson (id, name)

     

classable (class_id, classable_id, classable_type)

A class has several students and several lessons. a student can be in various classes and watch various lessons a lesson can be in various classes and be assisted by several students

When a student attends a lesson, a result is generated and in these results I want to include the name of the class that the student participates for which he attended the lesson. I do not know how to build this query in laravel using this relationship structure in the database.

edit 1:

Classe extends model {

 public function students() {
        return $this->morphedByMany(Student::class, 'classeable');
    }


    public function lessons() {
        return $this->morphedByMany(Lesson::class, 'classeable');
    }
}
Student extends model {

    public function classes(){

        return $this->morphToMany(Classe::class, 'classeable');

    }
}
Lesson extends model {

    public function classes(){

        return $this->morphToMany(Classe::class, 'classeable');

    }
}
    
asked by anonymous 20.02.2018 / 20:52

0 answers