laravel:數組手動分頁 --paginate()方法
阿新 • • 發佈:2019-01-04
inpu resp ren gin aware lse net pat slice
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()方法