83 lines
2.9 KiB
PHP
83 lines
2.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Api\V1\ModelParameter;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class CreateModelParameterRequest 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' => ['required', 'string', 'max:50', 'regex:/^[a-zA-Z][a-zA-Z0-9_]*$/'],
|
||
|
|
'label' => ['required', 'string', 'max:100'],
|
||
|
|
'type' => ['required', 'string', 'in:INPUT,OUTPUT'],
|
||
|
|
'data_type' => ['required', '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' => ['boolean'],
|
||
|
|
'display_order' => ['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
|
||
|
|
{
|
||
|
|
$this->merge([
|
||
|
|
'is_required' => $this->boolean('is_required'),
|
||
|
|
'display_order' => $this->integer('display_order', 0),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|