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']);
数据库为更新