Files
sam-api/app/Http/Requests/Api/V1/ModelParameter/UpdateModelParameterRequest.php

86 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests\Api\V1\ModelParameter;
use Illuminate\Foundation\Http\FormRequest;
class UpdateModelParameterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'name' => ['sometimes', 'string', 'max:50', 'regex:/^[a-zA-Z][a-zA-Z0-9_]*$/'],
'label' => ['sometimes', 'string', 'max:100'],
'type' => ['sometimes', 'string', 'in:INPUT,OUTPUT'],
'data_type' => ['sometimes', 'string', 'in:INTEGER,DECIMAL,STRING,BOOLEAN'],
'unit' => ['nullable', 'string', 'max:20'],
'default_value' => ['nullable', 'string', 'max:255'],
'min_value' => ['nullable', 'numeric'],
'max_value' => ['nullable', 'numeric', 'gte:min_value'],
'enum_values' => ['nullable', 'array'],
'enum_values.*' => ['string', 'max:100'],
'validation_rules' => ['nullable', 'string', 'max:500'],
'description' => ['nullable', 'string', 'max:500'],
'is_required' => ['sometimes', 'boolean'],
'display_order' => ['sometimes', 'integer', 'min:0'],
];
}
/**
* Get custom messages for validator errors.
*/
public function messages(): array
{
return [
'name.regex' => __('validation.model_parameter.name_format'),
'max_value.gte' => __('validation.model_parameter.max_value_gte_min'),
];
}
/**
* Get custom attribute names for validator errors.
*/
public function attributes(): array
{
return [
'name' => __('validation.attributes.parameter_name'),
'label' => __('validation.attributes.parameter_label'),
'type' => __('validation.attributes.parameter_type'),
'data_type' => __('validation.attributes.data_type'),
'unit' => __('validation.attributes.unit'),
'default_value' => __('validation.attributes.default_value'),
'min_value' => __('validation.attributes.min_value'),
'max_value' => __('validation.attributes.max_value'),
'enum_values' => __('validation.attributes.enum_values'),
'validation_rules' => __('validation.attributes.validation_rules'),
'description' => __('validation.attributes.description'),
'is_required' => __('validation.attributes.is_required'),
'display_order' => __('validation.attributes.display_order'),
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
if ($this->has('is_required')) {
$this->merge(['is_required' => $this->boolean('is_required')]);
}
if ($this->has('display_order')) {
$this->merge(['display_order' => $this->integer('display_order')]);
}
}
}