| Total Complexity | 5 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class EditLocation 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 | return Auth::user()->isUser(); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Get the validation rules that apply to the request. |
||
| 22 | * |
||
| 23 | * @return array |
||
| 24 | */ |
||
| 25 | public function rules() |
||
| 26 | { |
||
| 27 | return [ |
||
| 28 | 'name' => 'required|min:2|max:75|name', |
||
| 29 | ]; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get the validation rules that apply to the request. |
||
| 34 | * |
||
| 35 | * @return \Illuminate\Contracts\Validation\Validator |
||
| 36 | */ |
||
| 37 | protected function getValidatorInstance() |
||
| 38 | { |
||
| 39 | $validator = parent::getValidatorInstance(); |
||
| 40 | |||
| 41 | $validator->sometimes('site', 'integer|digits_between:1,10|exists:sites,id', function($input) { |
||
| 42 | return !$input->new_site_name && $input->site; |
||
| 43 | }); |
||
| 44 | |||
| 45 | $validator->sometimes('new_site_name', 'bail|min:2|max:190|name|unique:sites,name', function($input) { |
||
| 46 | return !$input->site; |
||
| 47 | }); |
||
| 48 | |||
| 49 | return $validator; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the error messages for the defined validation rules. |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public function messages() |
||
| 63 | ]; |
||
| 64 | } |
||
| 65 | } |