Initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreEngineRequest 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 [
|
||||
// Unikalność: nazwa + napięcie (jak legacy).
|
||||
'name' => ['required', 'string', 'max:128', Rule::unique('seg_engines', 'ENG_NAME')->where(fn ($q) => $q->where('ENG_VOLTAGE', $this->voltage))],
|
||||
'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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user