表单模型绑定关系

时间:2017-02-03 09:34:52

标签: laravel

  

我已经看过这篇文章,但我似乎无法做到:

     

Laravel form model binding

     

我收到此错误:

     

https://gyazo.com/2ea7b7bb6a19d588829447ee1a92053e我使用了laravel 5.2   对此。

     

一些截图:

     

https://gyazo.com/1b2c35e660dfe1aae69a02703733d083   https://gyazo.com/3d6f294473f6e54650a4a4403dc2777e   https://gyazo.com/a59aebc7362f51f9ac27852ea032f962

1 个答案:

答案 0 :(得分:0)

扩展我的评论:

你的问题在这里:

$user = User::where('id', $id) // Here more specifically, Laravel does not know if you mean id of users table or details table
    ->leftJoin('user_details', user_details.user_id', '=', 'users.id')
    ->first();

重写您的where语句,如下所示:

$user = User::where('users.id', $id)....

它应该有效。基本上,既然您已加入2个表并且他们都有id,那么您需要指定要查询的id

相关问题