我试图访问嵌套关系的子对象,从父对象返回许多结果.
假设我有4个模型:国家 - 省 - 城市 - 市政
他们的关系如下:
国家模式
class Country extends Eloquent
{
protected $table = 'countries';
public function provinces()
{
return $this->hasMany('Province');
}
}
Run Code Online (Sandbox Code Playgroud)
省模型
class Province extends Eloquent
{
protected $table = 'provinces';
public function cities()
{
return $this->hasMany('City');
}
public function country()
{
return $this->belongsTo('Country');
}
}
Run Code Online (Sandbox Code Playgroud)
城市模型
class City extends Eloquent
{
protected $table = 'cities';
public function municipalities()
{
return $this->hasMany('Municipality');
}
public function province()
{
return $this->belongsTo('Province');
}
}
Run Code Online (Sandbox Code Playgroud)
市政模式
class Municipality …Run Code Online (Sandbox Code Playgroud)