简体   繁体   English

在Laravel 5.1 Pagination中使用漂亮的URL

[英]Using pretty URLs with Laravel 5.1 Pagination

I am writing a website using the Laravel 5.1 framework, and I'm trying to figure out how to use pretty URLs ( pages/2 as opposed to pages?page=2 ). 我正在使用Laravel 5.1框架编写一个网站,我正在试图弄清楚如何使用漂亮的URL( pages/2而不是pages?page=2 )。 It actually surprised me that they haven't included a feature to allow this easily. 它实际上让我感到惊讶的是,他们没有包含一个功能来轻松实现这一点。

I'm also wondering, unless Laravel already handles this, how to set a limit on the number of links shown. 我也想知道,除非Laravel已经处理过这个问题,否则如何设置显示链接数量的限制。 I just want << 1 2 3 ... 657 658 659 >> , as an example. 我只想要<< 1 2 3 ... 657 658 659 >>作为例子。

Currently, my code is as follows: 目前,我的代码如下:

public function index() // I can pass the $page = 1 here (1 being default)
{
    $pages = Page::whereNotNull('approved')->orderBy('created_at', 'desc')->paginate(5);
    return view('pages.index', ['pages' => $pages]);
}

And in my view, I have {!! $pages->render() !!} 在我看来,我有{!! $pages->render() !!} {!! $pages->render() !!} at the end. {!! $pages->render() !!}最后。 This works perfectly in terms of using the GET variable, of course. 当然,这在使用GET变量方面非常有效。

I've tried to create a custom presenter extending BootstrapThreePresenter but I couldn't figure out how to link it in so everything worked. 我试图创建一个扩展BootstrapThreePresenter的自定义演示者,但我无法弄清楚如何链接它,所以一切正常。

I hasten to add, this question is not a duplicate as it applies to Laravel 5.1 - every other question I've looked at applies to Laravel 4.*. 我赶紧补充一下,这个问题并不重复,因为它适用于Laravel 5.1 - 我所看到的每个其他问题都适用于Laravel 4. *。

清除解决方案不存在,但有一些解决方法是这样的: Laravel分页漂亮的URL或者你可以检查是否有人为此创建了插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM