How to delete double quotes from double values ​when updating MYSQL JSON?

Viewed 68

I have some JSON keys which have double values ​​in JSON column.

When inserting to this field, it does not add double quotes to double values ​​in any way.

This is something I want.

But it doesn't behave the same when updating. I do these operations with illuminate/database. Below are specific data from my JSON column. (Column name is 'data')

{
  "test": 34.55,
  "test2": 44.99
}

While inserting double values, it successfully inserts as above. But when I update, it adds double quotes as below.

{
  "test": "34.55",
  "test2": "44.99"
}

When I examine the data I sent on the PHP side with the gettype() function, I can see that it is double.

So I am sure there is no problem with the data I am sending.

Also, It doesn't add double quotes when I send an integer value.

The database codes are as follows.

$this->table('table')
            ->where('id', $id)
            ->update([
                'data->test' => 34.55,
                'data->test2' => 44.99,
            ]);

Is there any way I can fix this?

1 Answers

I think you are casting the double as string, please double check on your model. My example below:

protected $casts = [
    'test' => 'double',
    'test2' => 'double'
];
Related