| Total Complexity | 4 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class ConfigRequest extends FormRequest |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Determine if the user is authorized to make this request. |
||
| 14 | * |
||
| 15 | * @return bool |
||
| 16 | */ |
||
| 17 | public function authorize() |
||
| 18 | { |
||
| 19 | return true; |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Get the validation rules that apply to the request. |
||
| 24 | * |
||
| 25 | * @return array |
||
| 26 | */ |
||
| 27 | public function rules() |
||
| 28 | { |
||
| 29 | $rules = [ |
||
| 30 | 'name' => 'required|max:50', |
||
| 31 | 'key' => ['required', 'max:100', 'regex:/^[\w]+$/'], |
||
| 32 | 'value' => 'max:2048', |
||
| 33 | 'type' => [ |
||
| 34 | Rule::in(array_keys(Config::$types)), |
||
| 35 | ], |
||
| 36 | ]; |
||
| 37 | if ((int) request()->input('type') === Config::TYPE_JSON) { |
||
| 38 | $rules['value'] = [ |
||
| 39 | 'required', |
||
| 40 | 'max:2048', |
||
| 41 | new JsonStr() |
||
| 42 | ]; |
||
| 43 | } |
||
| 44 | |||
| 45 | return $rules; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get custom messages for validator errors. |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function messages() |
||
| 59 | ]; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |