📜  laravel 的集合分页 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:25.188000             🧑  作者: Mango

代码示例1
// this goes to -> \app\Providers\AppServiceProvider -> boot function

        use Illuminate\Pagination\LengthAwarePaginator;
        use Illuminate\Support\Collection;

        Collection::macro('paginate', function($perPage, $total = null, $page = null, $pageName = 'page') {
            $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
            return new LengthAwarePaginator(
                $this->forPage($page, $perPage),
                $total ?: $this->count(),
                $perPage,
                $page,
                [
                    'path' => LengthAwarePaginator::resolveCurrentPath(),
                    'pageName' => $pageName,
                ]
            );
        });

    // this goes to controller. collection->paginate(1);
    $event->paginate(1);