Framework: Updating JSON column doesn't work with integer values

Created on 23 Oct 2016  路  4Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.19
  • PHP Version: 7.0.8
  • Database Driver & Version: Mysql 5.7.15

    Description:

Laravel ignores updating model if there is a JSON attribute with integer value and doesn't throw any exception. So these lines of code do nothing:

Product::find(1)
    ->update([
        'status' => $request->status,
        'properties->base_price' => 5400,
        'properties->option_price' => 120,
        'price' => 5400+120,
    ]);

I have to convert values to string to update JSON properties and these lines of code works fine:

Product::find(1)
    ->update([
        'status' => $request->status,
        'properties->base_price' => strval(5400),
        'properties->option_price' => strval(120),
        'price' => 5400+120,
    ]);

Steps To Reproduce:

Try to update a JSON column object property with an integer value.

Most helpful comment

All 4 comments

I would rather do it like this:

Product::find(1)
    ->update([
        'status' => $request->status,
        'properties' => [
            'base_price' => 5400,
            'option_price' => 120,
        ],
        'price' => 5400+120,
    ]);

I have same issue here, rather it is not working with Boolean too.

For example like this

 User::find(1)->update([
                'settings->push_notifications->follow' => 0
            ]);

Not event this

        User::find(1)->update([
            'settings' => [
                'push_notifications' => [
                    'follow' => 0
                ]
            ]
        ]);

@themsaid Update it is working fine for

        $user->update([
            'settings' => [
                'is_subscribed' => 0,
                'push_notifications' => [
                    'follow' => false,
                ]
            ],
        ]);

Is it possible to make it work like this as well.

        $user->update([
            'settings->is_subscribed'              => 0,
            'settings->push_notifications->follow' => true,
        ]);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

kerbylav picture kerbylav  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments