Laravel 5.5 Eloquent JSON update 无效

Larvale 和Mysql 版本:

Laravel 5.5
MySQL 5.7.22

migration: ext为json 格式:

            $table->json('ext')->nullable()->comment('额外的信息');

Sample Model 我设置了casts

   protected $casts = [
        'ext' => 'object'
    ];
>>> $sample = App\Entities\Sample::find(6);
=> App\Entities\Sample {#2947
     id: 6,
     surveyor_group_id: null,
     share_code: "2sssshell2o",
     code: "222221234526",
     name: "charlie",
     mobile: "xxxxxx",
     telephone: "xxx-xxxx",
     address: "8282891",
     location_id: null,
     ext: "{"hello": "word"}",
     created_at: "2018-07-26 03:21:52",
     updated_at: "2018-07-26 03:21:52",
   }
>>> $sample->update(['ext->hello'=>'nihao']);
=> true
>>> $sample
=> App\Entities\Sample {#2947
     id: 6,
     surveyor_group_id: null,
     share_code: "2sssshell2o",
     code: "222221234526",
     name: "charlie",
     mobile: "xxxxx",
     telephone: "xxx-xxxx",
     address: "8282891",
     location_id: null,
     ext: "{"hello": "word"}",
     created_at: "2018-07-26 03:21:52",
     updated_at: "2018-07-26 03:21:52",
   }

问题描述

>>> $sample->update(['ext->hello'=>'nihao']);

数据库为更新

JellyBool

确定设置了 fillable 了吗?

charlie 回复 JellyBool

找到相似的提问,应该是个bug。https://laracasts.com/discuss/channels/laravel/json-column-update-eloquent

写成:

$sample->update([
    'ext'=>[
        'hello'=>'world2'
        ]
   ]);

这样写是可以的