```
Orm::withCount(['relation as relation_sum' =>function($query){
$query->select(DB::raw("sum(amount) as relationsum"));
}])
```
## groupBy 对查询结果进行分组出现问题
找到 config/database.php 在 mysql 下面把 'strict' => true 改为 false。
## where in 数组
```
$Str = implode(',', $v);
$_where[] = [DB::raw("字段名 in ({$Str})"),'1'];
```
```
$where['status'] = 1;
$ids = [1, 2];
$where[] = [
function ($query) use ($ids) {
$query->whereIn('id', $ids);
},
];
$list = User::where($where)->get();
```
```
select * from `users` where (`status` = 1 and (`id` in (1, 2)))
```