简体   繁体   English

分页Laravel的每日统计资料

[英]Paginate the daily stats data in Laravel

I have a RAW query in Laravel 我在LaravelRAW查询

$sales = DB::table('orders')
             ->select(DB::raw('DATE(created_at) as date'), 
                      DB::raw('SUM(total_price) AS total_price'), 
                      'created_at')
             ->groupBy('date')
             ->orderBy('date', 'DESC')
             ->paginate(20);

I am trying to paginate the result set, but it shows me the following error; 我正在尝试对结果集进行分页,但是它显示了以下错误;

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'date' in 'group statement' 
(SQL: select count(*) as aggregate from `orders` group by `date`)

The above query works fine and returns me the complete result set when I replace; 上面的查询工作正常,并在我替换时返回完整的结果集;

paginate(20) with get() 使用get() paginate(20) get()

What is going on? 到底是怎么回事?

$sales = DB::table('orders')
             ->select(DB::raw('DATE(created_at) as `date`'), 
                      DB::raw('SUM(total_price) AS total_price'), 
                      'created_at')
             ->groupBy('date')
             ->orderBy('date', 'DESC')
             ->paginate(20);

Try this code, it should work. 试试这个代码,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM