0
這是我位置表:Laravel關係,一個數據庫有兩個外鍵
ID
Name
Type
這是路線表:
ID
Location_start(int)
Location_distination(int)
Distance
Rate
我嘗試實現它們之間的關係兩個表,所以我可以在foreach循環中獲取location_start
和location_distination
的位置名稱。我試過它:
public function locationStart()
{
$this->belongsTo('App\Route', 'location_start');
}
public function locationDistination()
{
$this->belongsTo('App\Route', 'location_distination');
}
但它沒有這樣工作。
請一)告訴我們列的,如果有的話,是外鍵和什麼他們引用b)你把這個(你發佈的關係)放在哪個模型中。 – devk
嘗試使用'hasOne'而不是'belongsTo'。 –
@devk Location_start和Location_distination。在位置模型 –