Laravel5中,手动分页

        $pageName = 'p';
        $perPage = 15;
        $currentPage = $request->input($pageName,1);
        $currentPath = $request->url();
        $offset = $perPage * ($currentPage - 1);
        $totalPages = DB::select('select count(*) as aggregate from posts')[0]->aggregate;
        $posts = DB::select('select * from posts limit :limit offset :offset',['limit'=>$perPage ,'offset'=>$offset]);
        $paginator = new LengthAwarePaginator($posts,$totalPages,$perPage,$currentPage,[
            'path' => $currentPath,
            'pageName' => $pageName,
        ]);
        return view('post', ['posts' => $paginator]);

 

你可能感兴趣的:(Laravel5中,手动分页)