如何匹配具有相同模型的两列?

时间:2020-05-14 12:19:29

标签: database laravel eloquent

我在下面有这两个表,我想在from代码和where代码之间建立关系,以便我可以使用$proc->from->name访问国家名称

我已经尝试过了,但是没用

public function from()
{
    return $this->hasOne('App\Country', 'from', 'code');
}

public function where()
{
    return $this->hasOne('App\Country', 'where', 'code');
}

过程:

id  | user_id   | from | where
--------------------------------
1   |    1      | GB   | US
2   |    2      | AZ   | TR

国家

id  | name         | code |
------------------------
1   |United States | US   |
2   |   France     | FR   | 

0 个答案:

没有答案
相关问题