Is it possible?
Consider this hypothetical relationship, for example:
A city has many schools. A school has many teachers. A teacher has many students. A student has many assignments.
With hasManyThrough, I can get all the students from a city
public function students() {
return $this->hasManyThrough(Student::class, Teacher::class);
}
but would it be possible to get all the assignments from a city?
I tried these two with no luck:
// City model
public function assignments() {
return $this->hasManyThrough(Assignment::class, Student::class);
}
(complains about there not being a foreign key for City on Students)
and:
// City model
public function assignments() {
return $this->hasManyThrough(Assignment::class, $this->students());
}
(fatal error)
Alternatively, if this type of relationship is not possible in an Eloquent model, how would you go about retrieving all assignments from a city in the best way?