lundi 23 mai 2016

Laravel Custom Pagination

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)

The first query I used was this one:

$goedeDoelen = GoedDoel::orderBy('punten', 'desc')->simplePaginate(5);

This worked pretty ok, only problem was that my ranking would reset everything I would go to a different page.

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.

I have tried to work around this by adding the ranking as an extra attribute to my Eloquent collections.

    $ranking = GoedDoel::orderBy('punten', 'desc')->get();
    foreach($ranking as $key => $item) {
        $item->ranking = $key+1;
    }

After that I tried to use ->simplePaginate() on my updated collection. This gave an error.

I have created a custom Paginator.

$goedeDoelen = new Paginator($ranking, 5);

This isn't working as intended. When I go to my second page, the URL messes up and goes to another view.

How can I make sure the Paginator knows what my current URL is to which it has to apply the ?page=2



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WOvRTS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire