Skill::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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