4

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

Forest
  • 938
  • 1
  • 11
  • 30
  • I'm pretty sure this would interfere with resource routing as resource routes would expect `/pages/2` to be the page with id 2. – Rob Oct 20 '15 at 14:45
  • @Rob That's a good point, actually. It wouldn't affect my particular application, but maybe it's a good idea to avoid things that could cause problems later. – Forest Oct 20 '15 at 14:54

1 Answers1

1

Clear solution doesn't exists, but there are some workarounds like this: Laravel pagination pretty URL or maybe you can check if someone created plugins for this.

Community
  • 1
  • 1
fico7489
  • 7,931
  • 7
  • 55
  • 89
  • I'll take a look. As I say, though, that solution is for Laravel 4, but I'll see if I can figure something out. – Forest Oct 20 '15 at 14:30