I seem to be unable to manually create an instance of the paginator.
use Illuminate\Pagination\Paginator;
class Blah {
public function index(Paginator $paginator)
{
// Build array
$var = $paginator->make($array, $count, 200);
return $var;
}
}
From here I'm just getting Unresolvable dependency resolving [Parameter #0 [ <required> $items ]] in class Illuminate\Pagination\Paginator
Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator. Could you explain parameters please? The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…
you can easily do it laravel pagination with array. step by step solution of laravel paginate from array. We will create our custom collection object with array and create pagination using laravel eloquent.
There is no more make() method in laravel 5. You need to create an instance of either an Illuminate\Pagination\Paginator
or Illuminate\Pagination\LengthAwarePaginator
. Take a look at documentation page, Creating A Paginator Manually part
http://laravel.com/docs/master/pagination
I guess it'll look something like this:
use Illuminate\Pagination\Paginator;
class Blah {
public function index()
{
// Build array
$array = [];
return new Paginator($array, $perPage);;
}
}
Also check this answer.
In 2019, to manualy paginate items in laravel you should instantiate Illuminate\Pagination\Paginator
class like this:
// array of items
$items = [ 'a' => 'ana', 'b' => 'bla', 'c' => 'cili' ];
// items per page
$perPage = 2;
// let paginator to regonize page number automaticly
// $currentPage = null;
// create paginator instance
$paginate = new Paginator($items, $perPage);
hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With