Closed jvbalcita closed 3 years ago
BelongsToThrough
relationships only return a single related model (i.e. one teacher).
You need to use a different package: https://github.com/staudenmeir/eloquent-has-many-deep
class Student extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function teachers()
{
return $this->hasManyDeep(
Teacher::class,
[Course::class, 'teacher_has_courses'],
['id'],
['course_id']
);
}
}
You are awesome @staudenmeir. You always save the day! :) Thank you!
Hi,
I don't know if I'm just making things complicated but I can't make this work.
I have a Course, Student and Teachers.
Student belongsTo > Course > belongsToMany > Teachers
And from student model I wanted to get directly the teachers
Thanks in advance.