laravel groupBy 分页
laravel groupBy 如何分页
项目中时间字段是用时间戳存储的,现在需要根据日期进行分页,但是将时间戳转为日期后分页页面会报错,因为分页首先会 count(*) 查询数据总量,没有对应的日期字段,从而报错,我们可以使用临时表来解决此事
代码如下:
$model=DB::table('tablebname')
->where(function($query) use ($res){
$query->where('xx','xx');
})
->selectRaw("area,from_unixtime(created_time,'%Y-%m-%d') as dates,sum(num) as use_num,path,desc")
->groupBy(['dates','area','path','money_id'])
->orderBy('dates','desc');
$data=DB::table(DB::raw("({$model->toSql()}) as temptable"))
->mergeBindings($model)
->paginate(15);