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
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());
Hello but I want to update all data, no where query. Is still that possible?
Well in theory yes. But it does seem like a bad idea :p
Invoices::where('id', '>', 0)->update($request->all());
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());
@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 sign in or create an account to participate in this conversation.