Completed
Push — main ( c5c3a9...be9d9d )
by Tan
18s queued 14s
created

ListPostResourceCollection::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 10
c 2
b 1
f 1
nc 1
nop 1
dl 0
loc 14
rs 9.9332
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Post;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Resources\Json\ResourceCollection;
7
use Illuminate\Pagination\LengthAwarePaginator;
8
9
class ListPostResourceCollection extends ResourceCollection
10
{
11
    /**
12
     * The resource that this resource collects.
13
     *
14
     * @var string
15
     */
16
    public $collects = ListPostResource::class;
17
18
    /**
19
     * Transform the resource collection into an array.
20
     *
21
     * @param  Request  $request
22
     *
23
     * @return array<string, mixed>
24
     */
25
    public function toArray(Request $request): array
26
    {
27
        /** @var LengthAwarePaginator<mixed> $paginator */
28
        $paginator = $this->resource;
29
30
        return [
31
            'data' => $this->collection,
32
            'meta' => [
33
                'total' => $paginator->total(),
34
                'per_page' => $paginator->perPage(),
35
                'current_page' => $paginator->currentPage(),
36
                'last_page' => $paginator->lastPage(),
37
                'from' => $paginator->firstItem(),
38
                'to' => $paginator->lastItem(),
39
            ],
40
        ];
41
    }
42
}
43