In the end, I had to code myself a Paginator. I am posting my solution here if it helps anyone.
Please note that the solution, while functional, requires some caution for practical use (validation); the class is simplified here to highlight the mechanism.
<?php namespace App\Services; use Illuminate\Support\Collection; use Illuminate\Pagination\BootstrapThreePresenter; use Illuminate\Pagination\LengthAwarePaginator as BasePaginator; class Paginator extends BasePaginator{ /** * Create a new paginator instance. * * @param mixed $items * @param int $perPage * @param string $path Base path * @param int $page * @return void */ public function __construct($items, $perPage, $path, $page){ // Set the "real" items that will appear here $trueItems = []; // That is, add the correct items for ( $i = $perPage*($page-1) ; $i < min(count($items),$perPage*$page) ; $i++ ){ $trueItems[] = $items[$i]; } // Set path as provided $this->path = $path; // Call parent parent::__construct($trueItems,count($items),$perPage); // Override "guessing" of page $this->currentPage = $page; } /** * Get a URL for a given page number. * * @param int $page * @return string */ public function url($page){ if ($page <= 0) $page = 1; return $this->path.$page; } }
To use a class, you can define a route
Route::get('items/{page}',' MyController@getElements ');
Then in the specified controller in getElements :
$items = new Paginator(Model::all(),$numberElementsPerPage,url('items'),$page);
Then you can dispose of your elements as usual. Note. I added a path option to integrate more complex projects with a good URL. Hope this helps!
source share