Reputation: 4525
According to the docs, I should be able to update records using update()
https://laravel.com/docs/5.4/queries#updates, but I'm getting the error Method update does not exist
.
Client::findOrFail($id)->update($request->all());
Any idea why?
Upvotes: 3
Views: 31051
Reputation: 488
Try This:
Client::find($id)->update($request->all());
Or you can use this:
Client::where('id',$id)->first()->update($request->all());
Upvotes: 3
Reputation: 512
I think this is because you are using the query builder's method on a single model object. You cannot do this because the findOrFail
method returns a single object that has nothing to do with query builder's methods.
Do it like this: Client::findOrFail($id)->first()->fill($request->all())->save();
Upvotes: 13