Mike Thrussell
Mike Thrussell

Reputation: 4525

Laravel update method does not exist

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

Answers (2)

Muhammad Rizwan
Muhammad Rizwan

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

HosseyNJF
HosseyNJF

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

Related Questions