Ad

Laravel Pagination Without A Model

- 1 answer

I found this reply this for a similar question: Laravel 5 - Manual pagination

what is not clear now to me is how to make the front page workin with the classic {{$items->links()}} on blade template.

my controller's code is:

$paginator = new Paginator($risultati, count($risultati),'10');

The problem is that the object that i generate is something like:

    LengthAwarePaginator {#311 ▼
  #total: 11
  #lastPage: 2
  #items: Collection {#312 ▶}
  #perPage: "10"
  #currentPage: 1
  #path: "/"
  #query: []
  #fragment: null
  #pageName: "page"
}

so the problem si in the "path", how can I make it works again? thanks a lot

Ad

Answer

You can use something like this to pass arguments to LengthAwarePaginator method:

$paginate = 20;

$page = Input::get('page', 1);

$offSet = ($page * $paginate) - $paginate;

$itemsForCurrentPage = array_slice($items, $offSet, $paginate, true);

$result = new \Illuminate\Pagination\LengthAwarePaginator ( $itemsForCurrentPage, count($items), $paginate, LengthAwarePaginator::resolveCurrentPage(),array('path' => LengthAwarePaginator::resolveCurrentPath()));

Ad
source: stackoverflow.com
Ad