Files
sam-api/app/Http/Requests/Api/V1/ModelFormula/CreateModelFormulaRequest.php

67 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests\Api\V1\ModelFormula;
use Illuminate\Foundation\Http\FormRequest;
class CreateModelFormulaRequest 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:100'],
'target_parameter' => ['required', 'string', 'max:50', 'regex:/^[a-zA-Z][a-zA-Z0-9_]*$/'],
'expression' => ['required', 'string', 'max:1000'],
'description' => ['nullable', 'string', 'max:500'],
'is_active' => ['boolean'],
'execution_order' => ['integer', 'min:0'],
];
}
/**
* Get custom messages for validator errors.
*/
public function messages(): array
{
return [
'target_parameter.regex' => __('validation.model_formula.target_parameter_format'),
];
}
/**
* Get custom attribute names for validator errors.
*/
public function attributes(): array
{
return [
'name' => __('validation.attributes.formula_name'),
'target_parameter' => __('validation.attributes.target_parameter'),
'expression' => __('validation.attributes.formula_expression'),
'description' => __('validation.attributes.description'),
'is_active' => __('validation.attributes.is_active'),
'execution_order' => __('validation.attributes.execution_order'),
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'is_active' => $this->boolean('is_active', true),
'execution_order' => $this->integer('execution_order', 0),
]);
}
}