Call to undefined method Illuminate\\Pagination\\P

2019-08-23 02:37发布

问题:

Here is my code:

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Input;
use Illuminate\Pagination\Paginator;
.
.
$collection = new Collection($guarantee_ticket);
// Paginate
$perPage = 3;
$currentPage = Input::get('page') - 1; // url.com/test?page=2
$pagedData = $collection->slice($currentPage * $perPage, $perPage)->all();
$pagination= Paginator::make($pagedData, count($collection), $perPage);

It throws:

Call to undefined method Illuminate\Pagination\Paginator::make()

And when I replace use Illuminate\Support\Facades\Paginator; with use Illuminate\Pagination\Paginator;, then it throws:

Class 'Illuminate\Support\Facades\Paginator' not found

Any idea how can I fix it?

回答1:

Class Illuminate\Pagination\Paginator doesn't have a make() method.

You instantiate it with the constructor. Also, 2nd parameter is perPage, 3rd is currentPage:

$pagination = new Paginator($pagedData, $perPage);

Documentation is definitely confusing, if not plainly wrong. It shows the Factory, but the view source links to Laravel 4.2 class, that is nonexistant in Laravel 5.6.