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 我设置了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']);
数据库为更新没有生效?各位大神是啥问题呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已经找到答案。看起来是一个 Laravel 的 bug
相似的问题:
https://laracasts.com/discuss...
Eloquent 应该写成:
DB class 可以写成