Completed
Push — main ( e8b4c6...9a4ea9 )
by Tan
16s queued 14s
created

PostNavigationResource::toArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 16
rs 9.9
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Post;
4
5
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
6
use CSlant\Blog\Core\Models\Post;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Resources\Json\JsonResource;
9
10
/**
11
 * Post Navigation Resource for previous/next navigation
12
 */
13
class PostNavigationResource extends JsonResource
14
{
15
    /**
16
     * @param  Request  $request
17
     *
18
     * @return array<string, mixed>
19
     */
20
    public function toArray($request): array
21
    {
22
        if (!$this->resource) {
23
            return [];
24
        }
25
26
        /** @var Post $this */
27
        return [
28
            'id' => $this->id,
29
            'name' => $this->name,
30
            'description' => $this->description,
31
            'slug' => $this->slug,
32
            'url' => $this->url,
33
            'image' => $this->image ? RvMedia::getImageUrl($this->image) : null,
34
            'created_at' => $this->created_at,
35
            'updated_at' => $this->updated_at,
36
        ];
37
    }
38
}
39