//控制器
$news = News::where('type_id',1)->where('is_del',1)->paginate(3);
//前端
@if($news->currentPage() == 1) @else <li><a href="{{url('news?page=1')}}">首页</a></li> <li><a href="{{$news->previousPageUrl()}}">上一页</a></li> <li><a href="{{$news->previousPageUrl()}}">{{$news->currentPage()-1}}</a></li> @endif <li><a class="active">{{$news->currentPage()}}</a></li> @if($news->currentPage() == $news->lastPage()) @else <li><a href="{{$news->nextPageUrl()}}">{{$news->currentPage()+1}}</a></li> <li><a href="{{$news->nextPageUrl()}}">下一页</a></li> <li><a href="{{url('news?page=').$news->lastPage()}}">尾页</a></li> @endif
//效果
//paginate()返回数据
'total' => $this->total(),
'per_page' => $this->perPage(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage(),
'next_page_url' => $this->nextPageUrl(),
'prev_page_url' => $this->previousPageUrl(),
'from' => $this->firstItem(),
'to' => $this->lastItem(),
'data' => $this->items->toArray(),
见 \vendor\laravel\framework\src\Illuminate\Pagination\LengthAwarePaginator.php
\vendor\laravel\framework\src\Illuminate\Pagination\Paginator.php
来自 https://blog.csdn.net/qq_39191303/article/details/80623670