|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Resources; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
|
6
|
|
|
use Jenssegers\Date\Date; |
|
7
|
|
|
|
|
8
|
|
|
class Experience extends JsonResource |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Transform the resource into an array. |
|
12
|
|
|
* |
|
13
|
|
|
* @param \Illuminate\Http\Request $request |
|
14
|
|
|
* @return array |
|
15
|
|
|
*/ |
|
16
|
|
|
public function toArray($request) |
|
17
|
|
|
{ |
|
18
|
|
|
$type = $this->experienceTypeName(); |
|
19
|
|
|
$translations = []; |
|
20
|
|
|
$dates = []; |
|
21
|
|
|
switch ($type) { |
|
22
|
|
|
case 'experience_work': |
|
23
|
|
|
$dates = [ |
|
24
|
|
|
'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
|
25
|
|
|
'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
|
26
|
|
|
]; |
|
27
|
|
|
break; |
|
28
|
|
|
case 'experience_award': |
|
29
|
|
|
$dates = [ |
|
30
|
|
|
'awarded_date' => $this->awarded_date ? $this->awarded_date->format('Y-m-d') : null, |
|
31
|
|
|
]; |
|
32
|
|
|
$translations = [ |
|
33
|
|
|
'award_recipient_type' => $this->award_recipient_type->getTranslations('name'), |
|
34
|
|
|
'award_recognition_type' => $this->award_recognition_type->getTranslations('name'), |
|
35
|
|
|
]; |
|
36
|
|
|
break; |
|
37
|
|
|
case 'experience_community': |
|
38
|
|
|
$dates = [ |
|
39
|
|
|
'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
|
40
|
|
|
'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
|
41
|
|
|
]; |
|
42
|
|
|
break; |
|
43
|
|
|
case 'experience_education': |
|
44
|
|
|
$dates = [ |
|
45
|
|
|
'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
|
46
|
|
|
'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
|
47
|
|
|
]; |
|
48
|
|
|
$translations = [ |
|
49
|
|
|
'education_status' => $this->education_status->getTranslations('name'), |
|
50
|
|
|
'education_type' => $this->education_type->getTranslations('name'), |
|
51
|
|
|
]; |
|
52
|
|
|
break; |
|
53
|
|
|
case 'experience_personal': |
|
54
|
|
|
$dates = [ |
|
55
|
|
|
'start_date' => $this->start_date ? $this->start_date->format('Y-m-d') : null, |
|
56
|
|
|
'end_date' => $this->end_date ? $this->end_date->format('Y-m-d') : null, |
|
57
|
|
|
]; |
|
58
|
|
|
break; |
|
59
|
|
|
} |
|
60
|
|
|
return array_merge( |
|
61
|
|
|
parent::toArray($request), |
|
62
|
|
|
$translations, |
|
63
|
|
|
[ |
|
64
|
|
|
'type' => $type, |
|
65
|
|
|
'experience_skills' => JsonResource::collection($this->whenLoaded('experience_skills')), |
|
66
|
|
|
], |
|
67
|
|
|
$dates |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|