Skill   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 9 1
1
<?php
2
3
namespace App\Http\Resources;
4
5
use Illuminate\Http\Resources\Json\JsonResource;
6
use App\Models\SkillCategory;
7
use Illuminate\Support\Facades\Log;
8
9
class Skill extends JsonResource
10
{
11
    /**
12
     * Transform the resource into an array.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @return array
16
     */
17
    public function toArray($request)
18
    {
19
        $skillArray = parent::toArray($request);
20
        // Want to include skill category ids, not the whole objects (to save data).
21
        unset($skillArray['skill_categories']);
22
        return array_merge($skillArray, [
23
            'skill_category_ids' => $this->when(
24
                $this->relationLoaded('skill_categories'),
25
                $this->skill_categories->pluck('id')->all()
26
            )
27
        ]);
28
    }
29
}
30