需要用到分页包
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\LengthAwarePaginator;
控制器中添加分页代码
$posts = $this->repository->findWhere($queryArray); $currentPage = Paginator::resolveCurrentPage() - 1; $perPage = 10; $currentPageSearchResults = $posts->slice($currentPage * $perPage, $perPage)->all(); $posts = new LengthAwarePaginator($currentPageSearchResults, count($posts), $perPage);
在视图当中进行使用
{!! $posts->setPath('/example-path')->appends(Request::except('page'))->render() !!}