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

ListPostResourceCollection   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 27
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 11 1
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