I want to update the available
to false
where toy->id=27
. Can any give me the laravel eloquent query for this? Thanks.
{
"color":"red",
"toy":{
"id":27,
"name":"Truck",
"price":12,
"available":true
},
"quantity":"12"
}
CodePudding user response:
In Postgresql you can use JSONB_SET like below:
update table set data=JSONB_SET(data, '{toy,available}','false') where data->'toy'->>'id'='27';
You can do this in DB::update i.e.
DB.update("update table set data=JSONB_SET(data, '{toy,available}','false') where data->'toy'->>'id'='27';
Ref: https://laravel.com/docs/8.x/database#database-transactions