armancs's avatar

Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically

Got this error when trying to update eloquent data.

Controller :

     public function update(Request $request, $id)
        {
         Invoices::update($request->all());
             Invoiceslist::whereId($id)->update($request->all());
         return redirect()->back();
     }

I am trying to update two table data called invoices and invoices list. there is multiple data against one invoices id.

Help me please

thanks

0 likes
6 replies
bobbybouwmann's avatar
Level 88

You can't do this

Invoices::update($request->all());

This call basically means, update all Invoices models with the given data. That is not what you want!

Instead, you need to do something like this

Invoices::where('id', $id)->update($request->all());
5 likes
Bossino's avatar

Hello but I want to update all data, no where query. Is still that possible?

Sinnbeck's avatar

Well in theory yes. But it does seem like a bad idea :p

Invoices::where('id', '>', 0)->update($request->all());
Redtama's avatar

If you do want to update all rows for a given model, a clean approach that avoids unnecessary where clauses would be:

Invoices::query()->update($request->all());
Snapey's avatar

@Redtama what a dumb answer. Sorry , why would you want to set every single invoice to the values specified by the user? This is dangerous and inappropriate advice.

Please or to participate in this conversation.