I'm working on a small project using PHP and Laravel I try to update my model but I'm getting an error message :
message "Non-static method Illuminate\\Database\\Eloquent\\Model::update() should not be called statically"
This is my code :
AttributeOption::update(array_merge([
'sort_order' => $sortOrder ,
], $optionInputs), $optionId);
CodePudding user response:
You're using update()
wrong.
mass update with conditions:
YourModel::where(/* some conditions */)
->update([
'field1' => 'value1',
'field2' => 'value2',
...
]);
mass update with no conditions
YourModel::query()
->update([
'field1' => 'value1',
'field2' => 'value2',
...
]);
single model update
$model = YourModel::where(/* some conditions */)->first();
$model->update([
'field1' => 'value1',
'field2' => 'value2',
...
]);
// Only accept fillable fields in the update
$model->fill([
'field1' => 'value1',
'field2' => 'value2',
...
])->save();
// Disregard fillable fields in the update
$model->forceFill([
'field1' => 'value1',
'field2' => 'value2',
...
])->save();