码迷,mamicode.com
首页 > 编程语言 > 详细

laravel:数组手动分页 --paginate()方法

时间:2019-01-03 22:43:56      阅读:502      评论:0      收藏:0      [点我收藏+]

标签:gen   als   paginati   pat   分页   json   article   turn   http   

use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator; 
$perPage = 10; //每页显示数量
if ($request->has(‘page‘)) {
$current_page = $request->input(‘page‘);
$current_page = $current_page <= 0 ? 1 :$current_page;
} else {
$current_page = 1;
}
$item = array_slice($Array, ($current_page-1)*$perPage, $perPage);//$Array为要分页的数组
$totals = count($Array);
$paginator =new LengthAwarePaginator($item, $totals, $perPage, $current_page, [
‘path‘ => Paginator::resolveCurrentPath(),
‘pageName‘ => ‘page‘,
]);

return response()->json([‘code‘=> 200,‘msg‘=>‘ok‘,‘data‘=>$paginator]);
---------------------
https://blog.csdn.net/qq_39191303/article/details/80564135

laravel:数组手动分页 --paginate()方法

标签:gen   als   paginati   pat   分页   json   article   turn   http   

原文地址:https://www.cnblogs.com/kaka666/p/10217184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!