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。在位置模型 –