Eloquent ORM关联关系 求教


按文档里面写的:
如果user的主键是id,phone与user是一对一,phone通过user_id与user的id一一对应,
那么return $this->hasOne('App\Phone', 'foreign_key', 'local_key');就应该写成:
return $this->hasOne('App\Phone', 'user_id', 'id');
可是事实上我在程序里反过来写才对:
return $this->hasOne('App\Phone', 'id', 'user_id');
这到底是为什么?是我理解错了吗?


点赞 取消点赞 收藏 取消收藏

<< 上一篇: eloquent update 一个写法

>> 下一篇: laravel5.3模板里用asset引入样式不行了?