6

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

Sturm
  • 4,105
  • 3
  • 24
  • 39

2 Answers2

16

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.

Community
  • 1
  • 1
mirzap
  • 445
  • 1
  • 6
  • 10
2

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.

Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46