Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
FlyShareAddToShortcutRequest | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
authorize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
failedAuthorization | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
rules | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace App\Http\Requests; |
4 | |
5 | use Illuminate\Auth\Access\AuthorizationException; |
6 | use Illuminate\Foundation\Http\FormRequest; |
7 | use Illuminate\Support\Facades\DB; |
8 | |
9 | class FlyShareAddToShortcutRequest extends FormRequest |
10 | { |
11 | /** |
12 | * Determine if the user is authorized to make this request. |
13 | */ |
14 | public function authorize(): bool |
15 | { |
16 | return DB::table('shortcuts')->where([ |
17 | ['reference_shares_shortcut_id', $this->sharesShortcut->_id], |
18 | ['user_id', request()->user()->getKey()], |
19 | ])->doesntExist(); |
20 | } |
21 | |
22 | /** |
23 | * Handle a failed authorization attempt. |
24 | * |
25 | * |
26 | * @throws \Illuminate\Auth\Access\AuthorizationException |
27 | */ |
28 | protected function failedAuthorization(): void |
29 | { |
30 | throw new AuthorizationException('This flyshare has been added to your flycuts already'); |
31 | } |
32 | |
33 | /** |
34 | * Get the validation rules that apply to the request. |
35 | */ |
36 | public function rules(): array |
37 | { |
38 | $rules = [ |
39 | 'category_id' => ['required'], |
40 | 'type' => 'required|string|in:category,sub_categories_lv1,sub_categories_lv2', |
41 | ]; |
42 | |
43 | switch ($this->type) { |
44 | case 'sub_categories_lv2': |
45 | array_push($rules['category_id'], 'exists:shortcut_sub_categories_lv2,_id'); |
46 | break; |
47 | case 'sub_categories_lv1': |
48 | array_push($rules['category_id'], 'exists:shortcut_sub_categories_lv1,_id'); |
49 | break; |
50 | |
51 | default: |
52 | array_push($rules['category_id'], 'exists:shortcut_categories,_id'); |
53 | break; |
54 | } |
55 | |
56 | return $rules; |
57 | } |
58 | } |