1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\ControlDB\Http\Controllers; |
||
4 | |||
5 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||
6 | use Illuminate\Foundation\Bus\DispatchesJobs; |
||
7 | use Illuminate\Foundation\Validation\ValidatesRequests; |
||
8 | use Illuminate\Pagination\LengthAwarePaginator; |
||
9 | use Illuminate\Routing\Controller as BaseController; |
||
10 | |||
11 | class Controller extends BaseController |
||
0 ignored issues
–
show
|
|||
12 | { |
||
13 | use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
||
14 | |||
15 | 28 | public function paginate($items) |
|
0 ignored issues
–
show
|
|||
16 | { |
||
17 | 28 | $perPage = request()->input('per_page', 10); |
|
18 | 28 | $page = request()->input('page', 1); |
|
19 | |||
20 | 28 | $slicedItems = collect($items)->forPage($page, $perPage)->values(); |
|
21 | |||
22 | 28 | return $this->paginationResponse($slicedItems, count($items)); |
|
23 | } |
||
24 | |||
25 | 36 | public function paginationResponse($items, $count) |
|
0 ignored issues
–
show
|
|||
26 | { |
||
27 | 36 | $perPage = request()->input('per_page', 10); |
|
28 | 36 | $page = request()->input('page', 1); |
|
29 | |||
30 | 36 | return (new LengthAwarePaginator( |
|
31 | 36 | $items, |
|
32 | $count, |
||
33 | $perPage, |
||
34 | $page, |
||
35 | 36 | ['path' => url(request()->path())] |
|
36 | 36 | ))->appends('per_page', $perPage); |
|
37 | } |
||
38 | } |
||
39 |