Answer the question
In order to leave comments, you need to log in
Communication "to many through". How to make a query to get the required data?
Hello everyone!)
My problem is this: there are three tables:
class Area extends Model
{
public function institutions()
{
return $this->hasManyThrough('App\Institution', 'App\City');
}
}
class City extends Model
{
public function institutions()
{
return $this->hasMany('App\Institution');
}
}
class Institution extends Model
{
public function area() {
return $this->belongsTo('App\Area');
}
}
$inst = Area::with('cities')->get();
foreach ($cities as $city) {
$city->institutions->name;
}
RelationNotFoundException in RelationNotFoundException.php line 20:
Call to undefined relationship [cities] on model [App\Area].
Answer the question
In order to leave comments, you need to log in
Looks like you didn't define a method for communication cities()
in the modelApp\Area
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question