1 // this goes to -> \app\Providers\AppServiceProvider -> boot function
2
3 use Illuminate\Pagination\LengthAwarePaginator;
4 use Illuminate\Support\Collection;
5
6 Collection::macro('paginate', function($perPage, $total = null, $page = null, $pageName = 'page') {
7 $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
8 return new LengthAwarePaginator(
9 $this->forPage($page, $perPage),
10 $total ?: $this->count(),
11 $perPage,
12 $page,
13 [
14 'path' => LengthAwarePaginator::resolveCurrentPath(),
15 'pageName' => $pageName,
16 ]
17 );
18 });
19
20 // this goes to controller. collection->paginate(1);
21 $event->paginate(1);
22