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

abhimanyusharma003's avatar

Json column update eloquent

I'm trying to update json column using eloquent but is not working.

Not working

        User::whereId(1)->update([
                'settings->push_notifications->follow' => false,
            ]);

Somehow if I use DB class, it works.

Works

        DB::table('users')
            ->where('id', 1)
            ->update([
            'settings->push_notifications->follow' => false
        ]);

Is it so that laravel don't support update of json column using eloquent ?

Here is JSON what that I would like to update

{
  "push_notifications": {
    "follow": true,
    "comment": true
  }
}
0 likes
3 replies
abhimanyusharma003's avatar
Level 5

Never Mind, It was a bug in Laravel and has been updated :)

It will work fine like this

       $user->update([
            'settings' => [
                'is_subscribed' => 0,
                'push_notifications' => [
                    'follow' => false,
                ]
            ],
        ]);
7 likes
nerman's avatar

You can use your original method to update a drilled-down json field:

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

Note the usage of -> syntax

4 likes
conradw's avatar

i came across to this while looking around for a similar problem. this helped me:

https://github.com/laravel/framework/issues/16505

it's expected that you need to add all fillable fields including the JSON ones, that way you can decide what JSON attributes you want to guard and what may be left fillable.

...which is very inconvenient. So i ended up doing just:

$user->forceFill([
    'settings->push_notifications->follow' => false
])->save();
9 likes

Please or to participate in this conversation.