Laravel ignores updating model if there is a JSON attribute with integer value and doesn't throw any exception. So these lines of code do nothing:
Product::find(1)
->update([
'status' => $request->status,
'properties->base_price' => 5400,
'properties->option_price' => 120,
'price' => 5400+120,
]);
I have to convert values to string to update JSON properties and these lines of code works fine:
Product::find(1)
->update([
'status' => $request->status,
'properties->base_price' => strval(5400),
'properties->option_price' => strval(120),
'price' => 5400+120,
]);
Try to update a JSON column object property with an integer value.
I would rather do it like this:
Product::find(1)
->update([
'status' => $request->status,
'properties' => [
'base_price' => 5400,
'option_price' => 120,
],
'price' => 5400+120,
]);
I have same issue here, rather it is not working with Boolean too.
For example like this
User::find(1)->update([
'settings->push_notifications->follow' => 0
]);
Not event this
User::find(1)->update([
'settings' => [
'push_notifications' => [
'follow' => 0
]
]
]);
Fix submitted: https://github.com/laravel/framework/pull/16068
@themsaid Update it is working fine for
$user->update([
'settings' => [
'is_subscribed' => 0,
'push_notifications' => [
'follow' => false,
]
],
]);
Is it possible to make it work like this as well.
$user->update([
'settings->is_subscribed' => 0,
'settings->push_notifications->follow' => true,
]);
Most helpful comment
Fix submitted: https://github.com/laravel/framework/pull/16068