title: Laravel Custom Pagination
body: <p>Having problems getting my pagination to work in Laravel 5.2 I use a foreach to generate a list of objects where each object has a certain ranking. (competition)</p>
  
  <p>The first query I used was this one:</p>
  
  <pre><code>$goedeDoelen = GoedDoel::orderBy('punten', 'desc')-&gt;simplePaginate(5);
  </code></pre>
  
  <p>This worked pretty ok, only problem was that my ranking would reset everything I would go to a different page.</p>
  
  <p>Example: Page 1 has objects from rank 1 - 5, page 2 should have ranks 6-10. By using the first Paginate method, the second page would have objects starting from 1 again.</p>
  
  <p>I have tried to work around this by adding the ranking as an extra attribute to my Eloquent collections.</p>
  
  <pre><code>    $ranking = GoedDoel::orderBy('punten', 'desc')-&gt;get();
      foreach($ranking as $key =&gt; $item) {
          $item-&gt;ranking = $key+1;
      }
  </code></pre>
  
  <p>After that I tried to use ->simplePaginate() on my updated collection. This gave an error.</p>
  
  <p>I have created a custom Paginator.</p>
  
  <pre><code>$goedeDoelen = new Paginator($ranking, 5);
  </code></pre>
  
  <p>This isn't working as intended. When I go to my second page, the URL messes up and goes to another view.</p>
  
  <p>How can I make sure the Paginator knows what my current URL is to which it has to apply the ?page=2</p>