Passed
Pull Request — main (#62)
by Tan
03:01
created

ListPostResourceCollection::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 11
rs 9.9666
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
8
class ListPostResourceCollection extends ResourceCollection
9
{
10
    /**
11
     * The resource that this resource collects.
12
     *
13
     * @var string
14
     */
15
    public $collects = ListPostResource::class;
16
17
    /**
18
     * Transform the resource collection into an array.
19
     *
20
     * @param  Request  $request
21
     *
22
     * @return array
23
     */
24
    public function toArray(Request $request): array
25
    {
26
        return [
27
            'data' => $this->collection,
28
            'meta' => [
29
                'total' => $this->resource->total(),
30
                'per_page' => $this->resource->perPage(),
31
                'current_page' => $this->resource->currentPage(),
32
                'last_page' => $this->resource->lastPage(),
33
                'from' => $this->resource->firstItem(),
34
                'to' => $this->resource->lastItem(),
35
            ],
36
        ];
37
    }
38
}
39