在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  PHP  數(shù)據(jù)庫  網(wǎng)絡(luò)安全/ Laravel 5.5 Eloquent JSON update 無效

Laravel 5.5 Eloquent JSON update 無效

參考資料

https://laravel-china.org/top...

問題背景

Larvale 和MySQL 版本:

Laravel 5.5
MySQL 5.7.22

migration: ext為json 格式:

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

Sample Model 我設(shè)置了casts

   protected $casts = [
        'ext' => 'object'
    ];

問題重現(xiàn)

>>> $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']);

數(shù)據(jù)庫為更新沒有生效?各位大神是啥問題呢?

回答
編輯回答
凹凸曼

已經(jīng)找到答案??雌饋硎且粋€ Laravel 的 bug

相似的問題:

https://laracasts.com/discuss...

Eloquent 應(yīng)該寫成:

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

DB class 可以寫成

$sample->update(['ext.hello'=>'world2']);
2018年5月7日 14:07