Answers for "laravel's collection pagination"

PHP
1

laravel's collection pagination

// 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);
Posted by: Guest on August-14-2021

Browse Popular Code Answers by Language