Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UpdateParameterRequest | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| rules | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| messages | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\v2\Parameter; |
| 4 | |
| 5 | use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin; |
| 6 | use Illuminate\Foundation\Http\FormRequest; |
| 7 | use Illuminate\Validation\Rule; |
| 8 | |
| 9 | /** |
| 10 | * Request for updating an existing parameter. |
| 11 | * |
| 12 | * @property string|null $name The unique name/key of the parameter (optional, unique except self) |
| 13 | * @property mixed $value The parameter value (optional, can be string, number, boolean, array, object, or null) |
| 14 | */ |
| 15 | class UpdateParameterRequest extends FormRequest |
| 16 | { |
| 17 | use AuthorizesVengresoAdmin; |
| 18 | |
| 19 | /** |
| 20 | * Get the validation rules that apply to the request. |
| 21 | * |
| 22 | * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
| 23 | */ |
| 24 | public function rules(): array |
| 25 | { |
| 26 | $parameterId = $this->route('parameter')?->id ?? $this->route('parameter'); |
| 27 | |
| 28 | return [ |
| 29 | 'name' => [ |
| 30 | 'sometimes', |
| 31 | 'string', |
| 32 | 'max:255', |
| 33 | Rule::unique('parameters', 'name')->ignore($parameterId, '_id'), |
| 34 | ], |
| 35 | 'value' => 'sometimes', |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get custom messages for validator errors. |
| 41 | * |
| 42 | * @return array<string, string> |
| 43 | */ |
| 44 | public function messages(): array |
| 45 | { |
| 46 | return [ |
| 47 | 'name.unique' => 'A parameter with this name already exists.', |
| 48 | ]; |
| 49 | } |
| 50 | } |