how to update json column using elequent laravel
This is example column [details_json]
[
{
"hex": "#FBE4D3",
"img": ["1.jpg", "2.jpg"],
"sizecount": [
["M", "S", "L"],
[21, 222, 221]
]
}, {
"hex": "#141310",
"img": ["3.jpg", "4.jpg"],
"sizecount": [
["Z", "E", "K"],
[11, 21, 22]
]
}
]
**How to update like this **
$model->update(['details_json->0->hex' => '#fff']);
$detailJson =
{
"hex": "#FBE4D3",
"img": ["1.jpg", "2.jpg"],
"sizecount": [
["M", "S", "L"],
[21, 222, 221]
]
}, {
"hex": "#141310",
"img": ["3.jpg", "4.jpg"],
"sizecount": [
["Z", "E", "K"],
[11, 21, 22]
]
}
];
$detailJson = json_decode($detailJson, 1);
$detailJson[0]['hex'] = '#FBE4D2';
model->update(['details_json' => json_encode($detailJson)]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.