56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StorePumpRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'q_n' => $this->dec($this->q_n),
|
|
'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', 'unique:seg_pumps,PUP_NAME'],
|
|
'manufacturer_id' => ['required', 'integer', 'exists:seg_manufacturers,MCF_ID'],
|
|
'q_n' => ['required', 'numeric', 'gt:0'],
|
|
// 8 punktów krzywych - H wymagane (>0), η wymagane (0 dozwolone przy Q=0).
|
|
'h' => ['required', 'array', 'size:8'],
|
|
'h.*' => ['required', 'numeric'],
|
|
'eta' => ['required', 'array', 'size:8'],
|
|
'eta.*' => ['required', 'numeric'],
|
|
'length' => ['nullable', 'numeric'],
|
|
'diameter' => ['nullable', 'numeric'],
|
|
'weight' => ['nullable', 'numeric'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'h.*.required' => 'Podaj wartość H dla każdego punktu Q.',
|
|
'eta.*.required' => 'Podaj wartość η dla każdego punktu Q.',
|
|
];
|
|
}
|
|
|
|
private function dec(mixed $v): ?string
|
|
{
|
|
return $v === null || $v === '' ? null : str_replace(',', '.', (string) $v);
|
|
}
|
|
}
|