laravel分页的链接是怎么写的代码?

比如一共有1000条数据,每页50条数据,一共20页,
就是下面这种:
首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页 共20页 到**页 跳转

JellyBool

直接使用:

//$articles = App\Article::paginate(15)是你的分页变量
//视图中展示
$articles->render();

这样就可以基本满足你的要求了,至于共多少页,可以使用:

$articles->count() // or $articles->total();
openwrtmail

在控制器里用paginate();方法实现分页。括号里的参数代表每一页多少条数据;例如
$articles = Article::latest()->published()->paginate(10);
然后在view里用render();方法,如 @JellyBool 说的那样。

 <nav class="nav-pagination">
        {!! $articles -> render() !!}
    </nav>
BigHeader

要是能把这些页面都做个缓存就好了,减轻数据库压力

zonghua

@openwrtmail 是直接渲染出来li元素?包括翻页跳转按钮?

openwrtmail

你引入bootstrap库后,使用pagination组建即可; @zonghua