How can I update an existing Eloquent relationship in Laravel 4?

后端 未结 4 685
情深已故
情深已故 2021-02-07 13:08

I am trying to update the relationship of a one-to-many relationship in Laravel. Unfortunately I couldn\'t find any documentation for it. Can anyone help me?

This is wha

4条回答
  •  我在风中等你
    2021-02-07 14:00

    Taylor Otwell's official answer is the following:

    $account = Account::find(99);
    User::find(1)->account()->associate($account)->save();
    

    I couldn't find the associate() method in the official docs. So if someone else is looking for a solution to this. Here you go!

提交回复
热议问题