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

66 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests\Api\V1\BomConditionRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateBomConditionRuleRequest 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:100'],
'ref_type' => ['sometimes', 'string', 'in:MATERIAL,PRODUCT'],
'ref_id' => ['sometimes', 'integer', 'min:1'],
'condition_expression' => ['sometimes', 'string', 'max:1000'],
'quantity_expression' => ['nullable', 'string', 'max:500'],
'waste_rate_expression' => ['nullable', 'string', 'max:500'],
'description' => ['nullable', 'string', 'max:500'],
'priority' => ['sometimes', 'integer', 'min:0'],
'is_active' => ['sometimes', '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
{
if ($this->has('is_active')) {
$this->merge(['is_active' => $this->boolean('is_active')]);
}
if ($this->has('priority')) {
$this->merge(['priority' => $this->integer('priority')]);
}
}
}