Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara96's avatar

JSON update query runs nothing changes in database?

In my database i have saved some data in post_image table. in that table there is a column image in that i save data like this.

[{"1": "[email protected]_1.jpeg"}, {"2": "[email protected]_2.jpg"}, {"3": "[email protected]_3.jpg"}, {"4": "[email protected]_4.jpg"}, {"5": "[email protected]_5.jpeg"}]

now i am trying to update the JSON key 1's value, Below query runs without any errors but nothing changes in database.

 $postImage = PostImage::where('post_id', $post->id)->update(["image->1" => "null"]);
0 likes
6 replies
Vilfago's avatar

"image->1" should be the database column. I think it's not.

Vilfago's avatar
Vilfago
Best Answer
Level 20

Yes...

Could you clean up your json, having something like {"1": "[email protected]_1.jpeg", "2": "[email protected]_2.jpg", "3": "[email protected]_3.jpg", "4": "[email protected]_4.jpg", "5": "[email protected]_5.jpeg"}?

$data_json = '{"1": "[email protected]_1.jpeg", "2": "[email protected]_2.jpg", "3": "[email protected]_3.jpg", "4": "[email protected]_4.jpg", "5": "[email protected]_5.jpeg"}';
$data = json_decode($data_json, TRUE);

unset($data[1]);
$data_to_save = json_encode($data);

$postImage = PostImage::where('post_id', $post->id)->update(["image" => $data_to_save]);

It will be easier.

lara96's avatar

@VILFAGO - Thank you Very much i cleaned up the JSON and it worked!!!

Please or to participate in this conversation.