hello guys
i hope u fine
in my project laravel
have 4 table
user
teacher
student
class
user has relation one to one with student and teacher
the table student anq teacher has relation with table class
i want find users (teacher,student) that are teaching and studying in same class
You can set up many to many relationships between a User and a Class using the students and teachers tables as intermediary.
class Class extends Model
{
public function studentUsers()
{
return $this->belongsToMany(User::class, 'students', 'user_id', 'class_id');
}
public function teacherUsers()
{
return $this->belongsToMany(User::class, 'teachers', 'user_id', 'class_id');
}
}
That might solve your problem. But I don't particularly like this design. What about using this package to assign users with teacher and student roles?