【发布时间】:2020-03-30 13:26:14
【问题描述】:
我的项目中有一些模型,在这张图片中详细描述了不同的关系:
我创建了一些模型来表示每个表。
我想知道是否有可能建立关系,允许恢复教师的所有学生或学生的所有教师。
例子:
class Student extends Model
{
public function clases(){
return $this->hasMany(Clase::class, 'student_id');
}
/** This function doesn't works, not the great relation */
public function teachers(){
return $this->hasManyThrough(Clase::class, Teacher::class, 'student_id', 'teacher_id');
}
}
我正在使用 Laravel 5.8
提前致谢
【问题讨论】:
标签: php sql laravel laravel-5 eloquent