slovenianGooner's avatar

Different paginations in L5

So,

Laravel uses the "SimpleBootstrapThreePresenter" as the default. The render method accepts others to, I was just wondering if this could be set as default or how would you pass other presenters to the render method?

0 likes
7 replies
calvinchoy's avatar

I would like to know more about the pagination also. I looked at the documentation and followed the steps for create custom presenter for zurb foundation but it didn't workout.

Also, when running the ->render() method to get the pagination I am only getting tow arrows.

Can anyone give the steps/example for creating the ranged pagination in L4?

bestmomo's avatar

I made this service for my paginations :

<?php namespace App\Services;

use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;

abstract class Pagination
{

  /**
   * Create paginator
   *
   * @param  Illuminate\Support\Collection  $collection
   * @param  int     $total
   * @param  int     $perPage
   * @return string
   */
  public static function makeLengthAware($collection, $total, $perPage, $appends = null)
  {
    $paginator = new LengthAwarePaginator(
      $collection, 
      $total, 
      $perPage, 
      Paginator::resolveCurrentPage(), 
      ['path' => Paginator::resolveCurrentPath()]
    );

    if($appends) $paginator->appends($appends);

    return str_replace('/?', '?', $paginator->render());
  }

}

You create links with :

$links = Pagination::makeLengthAware(Pagined Eloquent Collection, Total Count, Count per page);

You can append parameters with fourth parameter (for search it's nice).

bestmomo's avatar

@OzanKurt It was an answer for Calvinchoy. Ranged pagination was removed from L5, so I made this service, but now it's coming back so this service becomes useless.

Ozan's avatar

@bestmomo Thanks mate! Do we have any idea about when Laravel 5 becomes stable?

Please or to participate in this conversation.