1 | <?php |
||
2 | |||
3 | namespace App\Http\Requests; |
||
4 | |||
5 | use App\Models\ApplicationReview; |
||
6 | use Illuminate\Foundation\Http\FormRequest; |
||
7 | |||
8 | class BatchUpdateApplicationReview 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 === null) { |
||
19 | return false; |
||
20 | } |
||
21 | |||
22 | $inputIds = collect($this->all())->pluck('id')->all(); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
23 | $applicationReviews = ApplicationReview::whereIn('id', $inputIds)->get(); |
||
24 | |||
25 | foreach ($applicationReviews as $applicationReview) { |
||
26 | if (!$user->can('update', $applicationReview)) { |
||
27 | return false; |
||
28 | } |
||
29 | } |
||
30 | return true; |
||
31 | } |
||
32 | |||
33 | |||
34 | /** |
||
35 | * Get the validation rules that apply to the request. |
||
36 | * |
||
37 | * @return array |
||
38 | */ |
||
39 | public function rules() |
||
40 | { |
||
41 | return [ |
||
42 | '*.id' => 'required|exists:application_reviews,id', |
||
43 | '*.job_application_id' => 'required|exists:job_applications,id', |
||
44 | '*.review_status_id' => 'nullable|exists:review_statuses,id', |
||
45 | '*.notes' => 'nullable|string', |
||
46 | '*.department_id' => 'nullable|exists:departments,id', |
||
47 | '*.director_email_sent' => 'boolean', |
||
48 | '*.reference_email_sent' => 'boolean', |
||
49 | ]; |
||
50 | } |
||
51 | } |
||
52 |