46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdatePumpRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'length' => $this->dec($this->length),
|
|
'diameter' => $this->dec($this->diameter),
|
|
'weight' => $this->dec($this->weight),
|
|
'h' => collect($this->h ?? [])->map(fn ($v) => $this->dec($v))->all(),
|
|
'eta' => collect($this->eta ?? [])->map(fn ($v) => $this->dec($v))->all(),
|
|
]);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:128', Rule::unique('seg_pumps', 'PUP_NAME')->ignore($this->route('pump'))],
|
|
'manufacturer_id' => ['required', 'integer', 'exists:seg_manufacturers,MCF_ID'],
|
|
'length' => ['nullable', 'numeric'],
|
|
'diameter' => ['nullable', 'numeric'],
|
|
'weight' => ['nullable', 'numeric'],
|
|
'h' => ['nullable', 'array'],
|
|
'h.*' => ['nullable', 'numeric'],
|
|
'eta' => ['nullable', 'array'],
|
|
'eta.*' => ['nullable', 'numeric'],
|
|
];
|
|
}
|
|
|
|
private function dec(mixed $v): ?string
|
|
{
|
|
return $v === null || $v === '' ? null : str_replace(',', '.', (string) $v);
|
|
}
|
|
}
|