找到相似的提问,应该是个bug。https://laracasts.com/discuss/channels/laravel/json-column-update-eloquent
写成:
$sample->update([
'ext'=>[
'hello'=>'world2'
]
]);
这样写是可以的
Laravel 5.5
MySQL 5.7.22
$table->json('ext')->nullable()->comment('额外的信息');
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']);
数据库为更新
历史遗留系统,需要新增功能。比较被动。
records
表中有一个 column
叫 value
,里面存的是一个字符串,类似:{ number: 20}
.
现在需要对这个表进行 where 筛选,筛选出 value 里 number < 100 的。
Laravel Query 该怎么写呢?
注意:Laravel 5.2 Mysql 5.6 不支持 json query。
package可以通过config文件来给外界定义User Model
public function users()
{
return $this->belongsToMany(config('article_manager.users.model'));
}
config/article.php
{
users:
{
model: 'App\User'
}
}
在包内定义一个trait可以在项目User中用,但是在Article中咋用trait呢?没想明白,在Article中怎么补上belongsToMany?
laravel Package开发,如何处理一个包内的Model和包外Model的多对多关系?
例如:
比如我们要写一个很牛逼的Article的Package,这个包主要提供管理文章的相关功能。
如果别人也要写博客网站用到Article功能,可以直接用我们的package。
但是在某些用了我们这个Article包的项目中,我们希望Article要跟项目中的User建立多对多关系,我们如何在Package的Article下定义好多对多关系呢?
对于Article这个Pakcage,User这个Model不一定会存在。
这个应该是可以让你把laravel做成命令行交互的软件?
最近想学习一下微服务,有没有相关的经验或者示例供学习?
如何实现认证微服务,如何实现API Gateway,API Gateway如何管理其他micro services。
肯请有经验的人分享一下
stackoverflow有一个提问,但是没有回答:https://stackoverflow.com/questions/47015950/lumen-auth-microservice