Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
CategoryResource
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 toArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace App\Http\Resources\V1;
4
5use Illuminate\Http\Request;
6use Illuminate\Http\Resources\Json\JsonResource;
7
8class CategoryResource extends JsonResource
9{
10    public function toArray(Request $request): array
11    {
12        return [
13            'id' => $this->id,
14            'name' => $this->name,
15            'slug' => $this->slug,
16            'thumbnail' => $this->thumbnail ? (str_starts_with($this->thumbnail, 'http') ? $this->thumbnail : asset($this->thumbnail)) : null,
17            'parent_id' => $this->parent_id,
18            'children' => $this->whenLoaded('children', fn () => CategoryResource::collection($this->children)),
19        ];
20    }
21}