"image->1" should be the database column. I think it's not.
Feb 3, 2019
6
Level 1
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"]);
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.
Please or to participate in this conversation.