I’m trying to update the value of a json
column type for all of my users, my query that I’m running through Tinker doesn’t give any errors, it just returns 0
and the columns remain unchanged, what am I doing wrong?
JavaScript
x
User::where('notification_preferences')->update(['notification_preferences' => [
'domains' => [
'expiry' => [
'mail' => true,
'database' => true
]
]
]])
My columns on my rows currently has the value of…
JavaScript
{
"expiry_alerts": true
}
Advertisement
Answer
After I have read the comment below it came clear to me that you used the wrong syntax for the WHERE query of a JSON column. You have to use the -> operator.
For further information please see https://mattstauffer.com/blog/new-json-column-where-and-update-syntax-in-laravel-5-3/ & https://laravel.com/docs/8.x/queries#json-where-clauses
It should work like this:
JavaScript
User::where('notification_preferences->expiry-alerts',true)->update(['notification_preferences' => [
'domains' => [
'expiry' => [
'mail' => true,
'database' => true
]
]
]])