mardi 20 octobre 2015

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). 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. I just want << 1 2 3 ... 657 658 659 >>, as an example.

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() !!} at the end. This works perfectly in terms of using the GET variable, of course.

I've tried to create a custom presenter extending BootstrapThreePresenter but I couldn't figure out how to link it in so everything worked.

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.*.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire