1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Requests; |
4
|
|
|
|
5
|
|
|
use App\Models\ExperienceAward; |
6
|
|
|
use App\Models\ExperienceCommunity; |
7
|
|
|
use App\Models\ExperienceEducation; |
8
|
|
|
use App\Models\ExperiencePersonal; |
9
|
|
|
use App\Models\ExperienceSkill; |
10
|
|
|
use App\Models\ExperienceWork; |
11
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
12
|
|
|
use Illuminate\Validation\Rule; |
13
|
|
|
|
14
|
|
|
class BatchStoreExperienceSkill extends FormRequest |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Determine if the user is authorized to make this request. |
18
|
|
|
* |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
|
|
public function authorize() |
22
|
|
|
{ |
23
|
|
|
$user = $this->user(); |
24
|
|
|
if (!$user->can('create', ExperienceSkill::class)) { |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$experienceSkills = $this->all(); |
29
|
|
|
foreach ($experienceSkills as $experienceSkill) { |
30
|
|
|
$experience_type = $experienceSkill['experience_type']; |
31
|
|
|
$experience_id = (int)$experienceSkill['experience_id']; |
32
|
|
|
$experience = null; |
33
|
|
|
switch ($experience_type) { |
34
|
|
|
case 'experience_work': |
35
|
|
|
$experience = ExperienceWork::find($experience_id); |
36
|
|
|
break; |
37
|
|
|
case 'experience_award': |
38
|
|
|
$experience = ExperienceAward::find($experience_id); |
39
|
|
|
break; |
40
|
|
|
case 'experience_community': |
41
|
|
|
$experience = ExperienceCommunity::find($experience_id); |
42
|
|
|
break; |
43
|
|
|
case 'experience_education': |
44
|
|
|
$experience = ExperienceEducation::find($experience_id); |
45
|
|
|
break; |
46
|
|
|
case 'experience_personal': |
47
|
|
|
$experience = ExperiencePersonal::find($experience_id); |
48
|
|
|
break; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($experience === null || |
52
|
|
|
$user === null || |
53
|
|
|
!$user->can('update', $experience) |
54
|
|
|
) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the validation rules that apply to the request. |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function rules() |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'*.skill_id' => 'required|exists:skills,id', |
71
|
|
|
'*.justification' => 'nullable|string', |
72
|
|
|
'*.experience_type' => [' |
73
|
|
|
required', |
74
|
|
|
Rule::in([ |
75
|
|
|
'experience_work', |
76
|
|
|
'experience_award', |
77
|
|
|
'experience_community', |
78
|
|
|
'experience_personal', |
79
|
|
|
'experience_education' |
80
|
|
|
]) |
81
|
|
|
], |
82
|
|
|
'*.experience_id' => 'required|integer' |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|