1 | <?php |
||
2 | |||
3 | namespace App\Http\Resources; |
||
4 | |||
5 | use App\Repositories\CandidatesRepository; |
||
6 | use App\Utils\PhoneFormatter; |
||
7 | use Illuminate\Http\Resources\Json\JsonResource; |
||
8 | |||
9 | class CandidateResource extends JsonResource |
||
10 | { |
||
11 | /** |
||
12 | * Transform the resource into an array. |
||
13 | * |
||
14 | * @param \Illuminate\Http\Request $request |
||
15 | * |
||
16 | * @return array |
||
17 | */ |
||
18 | public function toArray($request) |
||
19 | { |
||
20 | return [ |
||
21 | 'id' => $this->id, |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
22 | 'created_at' => $this->created_at, |
||
0 ignored issues
–
show
The property
created_at does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
23 | 'updated_at' => $this->updated_at, |
||
0 ignored issues
–
show
The property
updated_at does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
24 | 'name' => $this->name, |
||
0 ignored issues
–
show
The property
name does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
25 | 'email' => $this->email, |
||
0 ignored issues
–
show
The property
email does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
26 | 'phone_number' => PhoneFormatter::format($this->phone_number), |
||
0 ignored issues
–
show
The property
phone_number does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
27 | 'future_agreement' => $this->future_agreement, |
||
0 ignored issues
–
show
The property
future_agreement does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
28 | 'path_to_cv' => $this->path_to_cv, |
||
0 ignored issues
–
show
The property
path_to_cv does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
29 | 'source_id' => $this->source_id, |
||
0 ignored issues
–
show
The property
source_id does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
30 | 'recruitment_id' => $this->recruitment_id, |
||
0 ignored issues
–
show
The property
recruitment_id does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
31 | 'source_recruitment_id' => $this->source_recruitment_id, |
||
0 ignored issues
–
show
The property
source_recruitment_id does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
32 | 'stage_id' => $this->stage_id, |
||
0 ignored issues
–
show
The property
stage_id does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
33 | 'rate' => $this->rate, |
||
0 ignored issues
–
show
The property
rate does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
34 | 'otherApplications' => $this->otherApplications(), |
||
35 | 'source' => $this->source, |
||
0 ignored issues
–
show
The property
source does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
36 | 'recruitment' => $this->recruitment, |
||
0 ignored issues
–
show
The property
recruitment does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
37 | 'stage' => $this->stage, |
||
0 ignored issues
–
show
The property
stage does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
38 | 'custom_fields' => json_decode($this->custom_fields), |
||
0 ignored issues
–
show
The property
custom_fields does not exist on App\Http\Resources\CandidateResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
39 | ]; |
||
40 | } |
||
41 | |||
42 | protected function otherApplications() |
||
43 | { |
||
44 | $allowedFields = ['id', 'created_at', 'recruitment_id', 'stage_id', 'recruitment']; |
||
45 | |||
46 | $otherApplications = CandidatesRepository::getOtherApplications($this->resource); |
||
47 | $filtered = []; |
||
48 | |||
49 | foreach ($otherApplications as $application) { |
||
50 | $filtered[] = array_intersect_key($application->toArray(), array_flip($allowedFields)); |
||
51 | } |
||
52 | |||
53 | return $filtered; |
||
54 | } |
||
55 | } |
||
56 |