如何获得分页结果中查询结果的总数。laravel分页与DB :: select
ex:$result=DB::select("select * from table");
$pagination = new Paginator($result, $resultsPerPage, $currentPage);
上面的一个给我resultsperpage和当前页面,但如何计算总数。
第四个参数要求作为数组类型我试过但它不工作。 我需要这样的结果。
{
"total": 32,
"per_page": 4,
"current_page": 1,
"last_page": 8,
"next_page_url": "http://192.168.0.117/projects/videoSharingApp/VSA/public/me/videos?page=2",
"prev_page_url": null,
"from": 1,
"to": 4,
}
您是使用刀片文件中的结果还是使用'JSON'响应返回结果?你能显示你的控制器的代码吗? –
上面的一个是从JSON响应,如果我使用这个$ pagination =新的Paginator($结果,$ resultsPerPage,$ currentPage);我在json结果中得到了没有“total”的上述结果。我只需要在我的json列表中完成。 – srivat1