35 lines
1 KiB
PHP
35 lines
1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Modules\CustomField\Requests;
|
||
|
|
|
||
|
|
use App\Modules\CustomField\Models\CustomFieldDefinition;
|
||
|
|
use App\Modules\CustomField\Models\CustomFieldType;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Validation\Rule;
|
||
|
|
|
||
|
|
class UpdateCustomFieldValueRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool { return true; }
|
||
|
|
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
/** @var CustomFieldDefinition $definition */
|
||
|
|
$definition = $this->route('customFieldDefinition');
|
||
|
|
|
||
|
|
$valueRules = $definition->is_required ? ['required'] : ['nullable'];
|
||
|
|
|
||
|
|
$valueRules[] = match ($definition->type) {
|
||
|
|
CustomFieldType::Number => 'numeric',
|
||
|
|
CustomFieldType::Date => 'date',
|
||
|
|
CustomFieldType::Select => Rule::in($definition->options ?? []),
|
||
|
|
default => 'string',
|
||
|
|
};
|
||
|
|
|
||
|
|
if (in_array($definition->type, [CustomFieldType::Text, CustomFieldType::Textarea], true)) {
|
||
|
|
$valueRules[] = 'max:65535';
|
||
|
|
}
|
||
|
|
|
||
|
|
return ['value' => $valueRules];
|
||
|
|
}
|
||
|
|
}
|