【发布时间】:2018-12-05 21:45:00
【问题描述】:
我有一个如下查询,它按预期工作。我在这里使用了havingRaw 选项来过滤结果。
$customers = Customer::select(DB::raw("`name`, `mobile`, `branch`, count(*) as total_orders"))
->groupBy('mobile')
->havingRaw('total_orders > 12')
->orderBy('total_orders', 'desc')
->get();
由于返回行的总数会有所不同,我需要将其显示为分页。所以我改变了如下查询。然后它显示找不到total_orders 列的错误。
$customers = Customer::select(DB::raw("`name`, `mobile`, `branch`, count(*) as total_orders"))
->groupBy('mobile')
->havingRaw('total_orders > 12')
->orderBy('total_orders', 'desc')
->paginate();
我为以前版本的 Laravel 找到了一些解决方法。我的项目使用 Laravel 5.6,有什么解决方案吗?
【问题讨论】: