Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UpdateParameterRequest
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rules
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 messages
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\Parameter;
4
5use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin;
6use Illuminate\Foundation\Http\FormRequest;
7use 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 * @property string|null $metadata_key When set, exposes the parameter in the metadata API with this key name (set to null to remove from metadata)
15 */
16class UpdateParameterRequest extends FormRequest
17{
18    use AuthorizesVengresoAdmin;
19
20    /**
21     * Get the validation rules that apply to the request.
22     *
23     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
24     */
25    public function rules(): array
26    {
27        $parameterId = $this->route('parameter')?->id ?? $this->route('parameter');
28
29        return [
30            'name' => [
31                'sometimes',
32                'string',
33                'max:255',
34                Rule::unique('parameters', 'name')->ignore($parameterId, '_id'),
35            ],
36            'value' => 'sometimes',
37            'metadata_key' => 'sometimes|nullable|string|max:255',
38        ];
39    }
40
41    /**
42     * Get custom messages for validator errors.
43     *
44     * @return array<string, string>
45     */
46    public function messages(): array
47    {
48        return [
49            'name.unique' => 'A parameter with this name already exists.',
50        ];
51    }
52}