1 | <?php |
||
2 | |||
3 | namespace App\Http\Requests; |
||
4 | |||
5 | use App\Models\ExperienceSkill; |
||
6 | use Illuminate\Foundation\Http\FormRequest; |
||
7 | |||
8 | class BatchUpdateExperienceSkill extends FormRequest |
||
9 | { |
||
10 | /** |
||
11 | * Determine if the user is authorized to make this request. |
||
12 | * |
||
13 | * @return bool |
||
14 | */ |
||
15 | public function authorize() |
||
16 | { |
||
17 | $user = $this->user(); |
||
18 | if (!$user->can('create', ExperienceSkill::class)) { |
||
19 | return false; |
||
20 | } |
||
21 | |||
22 | $inputIds = collect($this->all())->pluck('id')->all(); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
23 | $experienceSkills = ExperienceSkill::with('experience')->whereIn('id', $inputIds)->get(); |
||
24 | foreach ($experienceSkills as $experienceSkill) { |
||
25 | if ($experienceSkill->experience === null || |
||
26 | $user === null || |
||
27 | !$user->can('update', $experienceSkill->experience) |
||
28 | ) { |
||
29 | return false; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | return true; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Get the validation rules that apply to the request. |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | public function rules() |
||
42 | { |
||
43 | return [ |
||
44 | '*.id' => 'required|exists:App\Models\ExperienceSkill,id', |
||
45 | '*.justification' => 'nullable|string', |
||
46 | ]; |
||
47 | } |
||
48 | } |
||
49 |