Php 调用成员函数,其中()是laravel中的整数

Php 调用成员函数,其中()是laravel中的整数,php,laravel,Php,Laravel,我在运行此代码时遇到此错误 public function update(StoreAccountsRequest $request, $id) { $user = User::findOrFail($id); $user->Accounts()->update($request->except('_method', '_token'))->where('accounts.user_id', '$user'); r

我在运行此代码时遇到此错误

public function update(StoreAccountsRequest $request, $id)
    {
        $user = User::findOrFail($id);

        $user->Accounts()->update($request->except('_method', '_token'))->where('accounts.user_id', '$user');
        return redirect()->route('accounts.index')->with(['message' => 'Accounts updated successfully']);
    }
请帮助我了解如何更新accounts表中的单个用户帐户

代码必须如下所示

$user->Accounts()->update($request->except('_method', '_token'));

查询生成器
update
返回受影响行数的整数,将
where
放在
update
之前。。。我会想象你没有一个
用户id
值为
“$user”
。。。关系已经在检查所需的外键,您的查询是向后的,但实际上不需要
where()
子句<代码>$user->accounts(),如果定义正确,将已经应用了
where()
子句(以及它的正确版本,
'$user'
)。如果你想更新一个账户,那么你需要通过关系的命名来确定你想要更新的特定账户,因为你似乎有很多