比如一共有1000条数据,每页50条数据,一共20页,就是下面这种:首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页 共20页 到**页 跳转
微信里点“发现”,扫一下
二维码便可将本文分享至朋友圈。
直接使用:
//$articles = App\Article::paginate(15)是你的分页变量 //视图中展示 $articles->render();
这样就可以基本满足你的要求了,至于共多少页,可以使用:
$articles->count() // or $articles->total();
在控制器里用paginate();方法实现分页。括号里的参数代表每一页多少条数据;例如 $articles = Article::latest()->published()->paginate(10); 然后在view里用render();方法,如 @JellyBool 说的那样。
$articles = Article::latest()->published()->paginate(10);
<nav class="nav-pagination"> {!! $articles -> render() !!} </nav>
要是能把这些页面都做个缓存就好了,减轻数据库压力
@openwrtmail 是直接渲染出来li元素?包括翻页跳转按钮?
你引入bootstrap库后,使用pagination组建即可; @zonghua
视频已录制,具体看看分页的实现方式 https://laravist.com/series/dive-a-little-deep-into-laravel-5/episodes/8