1
<?php
2

3
namespace Nuwave\Lighthouse\Pagination;
4

5
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
6
use Illuminate\Support\Collection;
7

8
class PaginatorField
9
{
10
    /**
11
     * Resolve paginator info for connection.
12
     *
13
     * @param  \Illuminate\Pagination\LengthAwarePaginator<mixed>  $root
14
     * @return array<string, mixed>
15
     */
16 1
    public function paginatorInfoResolver(LengthAwarePaginator $root): array
17
    {
18
        return [
19 1
            'count' => $root->count(),
20 1
            'currentPage' => $root->currentPage(),
21 1
            'firstItem' => $root->firstItem(),
22 1
            'hasMorePages' => $root->hasMorePages(),
23 1
            'lastItem' => $root->lastItem(),
24 1
            'lastPage' => $root->lastPage(),
25 1
            'perPage' => $root->perPage(),
26 1
            'total' => $root->total(),
27
        ];
28
    }
29

30
    /**
31
     * Resolve data for connection.
32
     *
33
     * @param  \Illuminate\Pagination\LengthAwarePaginator<mixed>  $root
34
     * @return \Illuminate\Support\Collection<mixed>
35
     */
36 1
    public function dataResolver(LengthAwarePaginator $root): Collection
37
    {
38
        // @phpstan-ignore-next-line static refers to the wrong class because it is a proxied method call
39 1
        return $root->values();
40
    }
41
}

Read our documentation on viewing source code .

Loading