调用未定义的方法 IlluminatePaginationPaginator::make()?

2022-01-04 00:00:00 php laravel pagination

这是我的代码:

use IlluminateSupportCollection;
use IlluminateSupportFacadesInput;
use IlluminatePaginationPaginator;
.
.
$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);

它抛出:

调用未定义的方法IlluminatePaginationPaginator::make()

Call to undefined method IlluminatePaginationPaginator::make()

当我将 use IlluminateSupportFacadesPaginator; 替换为 use IlluminatePaginationPaginator; 时,它会抛出:

And when I replace use IlluminateSupportFacadesPaginator; with use IlluminatePaginationPaginator;, then it throws:

找不到类 'IlluminateSupportFacadesPaginator'

Class 'IlluminateSupportFacadesPaginator' not found

知道如何修复它吗?

推荐答案

Class IlluminatePaginationPaginator 没有 make() 方法.

你用构造函数实例化它.另外,第二个参数是 perPage,第三个参数是 currentPage:

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

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

文档 绝对令人困惑,如果不是明显错误的话.它显示了工厂,但查看源链接到 Laravel 4.2 类,这在 Laravel 5.6 中不存在.

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.

相关文章