Home > OS >  Update a JSON field with eloquent?
Update a JSON field with eloquent?

Time:11-15

How can I update a JSON field with eloquent? The field casts to an array.

I cannot use update as I cannot make the field mass assignable.

I cannot to $myModel->myField = ["some" => "value"] as it will erase any other json data on the field.

CodePudding user response:

You can use forceFill() like this:

$myModel->forceFill(['myField->some' => 'value'])->save();
  • Related