Manually Creating a Paginator (Laravel 5)

2019-01-27 01:00发布

问题:

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

回答1:

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.