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');
}
}