You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Illuminate\Pagination\Paginator::make()报错:未定义该方法

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

Hey there, that error pops up because the Paginator::make() method was removed in Laravel 5.3 and later versions. Instead, you'll need to use the LengthAwarePaginator class to manually paginate your collection. Here's how to adjust your code:

Step 1: Update Your Import

Replace the Paginator import with LengthAwarePaginator:

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Input;
use Illuminate\Pagination\LengthAwarePaginator; // This is the replacement

Step 2: Rewrite the Pagination Logic

Here's the revised code that works with modern Laravel versions:

$collection = new Collection($guarantee_ticket);
$perPage = 3;

// Use the framework's built-in method to get the current page (more reliable than manual Input get)
$currentPage = LengthAwarePaginator::resolveCurrentPage();
// Calculate the starting index for slicing
$offset = ($currentPage - 1) * $perPage;
$pagedData = $collection->slice($offset, $perPage)->all();

// Create the paginator instance
$pagination = new LengthAwarePaginator(
    $pagedData,
    count($collection), // Total number of items
    $perPage, // Items per page
    $currentPage, // Current page number
    [
        'path' => LengthAwarePaginator::resolveCurrentPath(), // Ensures correct pagination URLs
    ]
);

Key Notes:

  • LengthAwarePaginator is designed for scenarios where you know the total number of items (exactly what your original code was doing with Paginator::make()).
  • Using resolveCurrentPage() and resolveCurrentPath() ensures your pagination works seamlessly with Laravel's request handling, avoiding issues with manual input parsing.
  • The path parameter is crucial—it tells the paginator what base URL to use for generating pagination links (e.g., url.com/test in your example).

内容的提问来源于stack exchange,提问作者Martin AJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:43:45