2017-09-27 53 views
0

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'); 
} 

哪裏錯了?

+0

城市()的關係在哪裏? –

+0

在Municipal_district.php中'公共職能城市() { return $ this-> belongsTo('App \ Models \ City','city_id'); } ' –

+0

它是否在Municipal_district.php? –

回答

0

城市模型

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

我解決了它,謝謝 –