Laravel手动分页的方法

use Illuminate\Pagination\LengthAwarePaginator;

public function index(Request $request){
    $list =[...];
    //当前页数 默认1
    $page = $request->page ?: 1;
    //每页的条数
    $perPage = 10;
    //计算每页分页的初始位置
     $offset = ($page * $perPage) - $perPage;
     //实例化LengthAwarePaginator类,并传入对应的参数
     $list = new LengthAwarePaginator(array_slice($list, $offset, 
     $perPage, true), count($list), $perPage,$page, ['path' => 
     '', 'query' => $request->query()]);
     return view('admin.user.index', compact('list'), 
     compact('query'));
}
    

 

posted @ 2019-09-10 14:22  郁冬  阅读(3176)  评论(0编辑  收藏  举报