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

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

转载于:https://www.cnblogs.com/kaka666/p/10217184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值