Files
2026-09-03 12:21:17 +02:00

45 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateEngineRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
foreach (['power', 'voltage', 'current', 'eta', 'cos_fi', 'rpm', 'length', 'weight', 'diameter'] as $f) {
$this->merge([$f => $this->dec($this->$f)]);
}
}
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:128', Rule::unique('seg_engines', 'ENG_NAME')->where(fn ($q) => $q->where('ENG_VOLTAGE', $this->voltage))->ignore($this->route('engine'))],
'manufacturer_id' => ['required', 'integer', 'exists:seg_manufacturers,MCF_ID'],
'power' => ['required', 'numeric'],
'voltage' => ['required', 'numeric'],
'current' => ['nullable', 'numeric'],
'eta' => ['nullable', 'numeric'],
'cos_fi' => ['nullable', 'numeric'],
'rpm' => ['nullable', 'numeric'],
'length' => ['nullable', 'numeric'],
'weight' => ['nullable', 'numeric'],
'diameter' => ['nullable', 'numeric'],
'wires' => ['nullable', 'string', 'max:32'],
];
}
private function dec(mixed $v): ?string
{
return $v === null || $v === '' ? null : str_replace(',', '.', (string) $v);
}
}