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
|
|
|
$result = true; |
24
|
|
|
$experienceSkills = $this->all(); |
25
|
|
|
foreach ($experienceSkills as $experienceSkill) { |
26
|
|
|
$experience_type = $experienceSkill['experience_type']; |
27
|
|
|
$experience_id = (int)$experienceSkill['experience_id']; |
28
|
|
|
$user = $this->user(); |
29
|
|
|
$experience = null; |
30
|
|
|
switch ($experience_type) { |
31
|
|
|
case 'experience_work': |
32
|
|
|
$experience = ExperienceWork::find($experience_id); |
33
|
|
|
break; |
34
|
|
|
case 'experience_award': |
35
|
|
|
$experience = ExperienceAward::find($experience_id); |
36
|
|
|
break; |
37
|
|
|
case 'experience_community': |
38
|
|
|
$experience = ExperienceCommunity::find($experience_id); |
39
|
|
|
break; |
40
|
|
|
case 'experience_education': |
41
|
|
|
$experience = ExperienceEducation::find($experience_id); |
42
|
|
|
break; |
43
|
|
|
case 'experience_personal': |
44
|
|
|
$experience = ExperiencePersonal::find($experience_id); |
45
|
|
|
break; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($experience === null || |
49
|
|
|
$user === null || |
50
|
|
|
!$user->can('create', ExperienceSkill::class) || |
51
|
|
|
!$user->can('update', $experience) |
52
|
|
|
) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $result; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the validation rules that apply to the request. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function rules() |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'*.skill_id' => 'required|exists:skills,id', |
69
|
|
|
'*.justification' => 'nullable|string', |
70
|
|
|
'*.experience_type' => [' |
71
|
|
|
required', |
72
|
|
|
Rule::in([ |
73
|
|
|
'experience_work', |
74
|
|
|
'experience_award', |
75
|
|
|
'experience_community', |
76
|
|
|
'experience_personal', |
77
|
|
|
'experience_education' |
78
|
|
|
]) |
79
|
|
|
], |
80
|
|
|
'*.experience_id' => 'required|integer' |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|