调用未定义的关系[城市]的模型[应用程序\型号\ Municipal_district]
问题描述:
City.php调用未定义的关系[城市]的模型[应用程序型号 Municipal_district]
public function municipal_districts()
{
return $this->hasMany('App\Models\Municipal_district');
}
Municipal_district.php
public function province()
{
return $this->belongsTo('App\Models\City', 'city_id');
}
哪里错了?
答
城市模型
public function municipal_districts()
{
return $this->hasMany('App\Models\Municipal_district');
}
Municipal_district型号
public function city()
{
return $this->belongsTo('App\Models\City', 'city_id');
}
而且我不knwo对城市()这里关系!
城市有很多ditricts和区属于一个城市。那么,这里的城市()是什么?
+0
我失败了这个功能'公共职能省()'不proviice(),但是城市() –
+0
我解决了它,谢谢 –
城市()的关系在哪里? –
在Municipal_district.php中'公共职能城市() { return $ this-> belongsTo('App \ Models \ City','city_id'); } ' –
它是否在Municipal_district.php? –