【发布时间】:2014-05-09 23:53:56
【问题描述】:
MySQL 有一个功能可以获取查询返回的记录总数,没有限制,SQL_CALC_FOUND_ROWS。 Laravel 支持吗?
目前我必须在两个查询中做到这一点:
public function dataTable() {
$bookings = DB::table('bookings')
->limit(Input::query('iDisplayLength'))
->offset(Input::query('iDisplayStart'))
->get();
$count = $bookings = DB::table('bookings')
->count();
return Response::json([
'iTotalRecords' => $count,
]);
}
这不仅会降低效率,而且一旦我添加了所有->where() 标准,就会有很多冗余代码。
【问题讨论】:
-
你想要这个 Laravel Datatable 包的解决方案吗?如果是的话,有一个基本的解决方案。
-
@Yilmazerhakan 不,谢谢。对于我的需求来说,这看起来过于复杂。我不介意知道它们是如何计算的——它们都是单独的查询吗?
标签: php mysql laravel laravel-4