Files
sam-api/app/Http/Requests/Api/V1/BomConditionRule/CreateBomConditionRuleRequest.php

63 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests\Api\V1\BomConditionRule;
use Illuminate\Foundation\Http\FormRequest;
class CreateBomConditionRuleRequest 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'],
'ref_type' => ['required', 'string', 'in:MATERIAL,PRODUCT'],
'ref_id' => ['required', 'integer', 'min:1'],
'condition_expression' => ['required', 'string', 'max:1000'],
'quantity_expression' => ['nullable', 'string', 'max:500'],
'waste_rate_expression' => ['nullable', 'string', 'max:500'],
'description' => ['nullable', 'string', 'max:500'],
'priority' => ['integer', 'min:0'],
'is_active' => ['boolean'],
];
}
/**
* Get custom attribute names for validator errors.
*/
public function attributes(): array
{
return [
'name' => __('validation.attributes.rule_name'),
'ref_type' => __('validation.attributes.ref_type'),
'ref_id' => __('validation.attributes.ref_id'),
'condition_expression' => __('validation.attributes.condition_expression'),
'quantity_expression' => __('validation.attributes.quantity_expression'),
'waste_rate_expression' => __('validation.attributes.waste_rate_expression'),
'description' => __('validation.attributes.description'),
'priority' => __('validation.attributes.priority'),
'is_active' => __('validation.attributes.is_active'),
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'is_active' => $this->boolean('is_active', true),
'priority' => $this->integer('priority', 0),
]);
}
}