gruene-seele/app/Http/Requests/Inventory/UpdatePackagingItemRequest.php

45 lines
1.4 KiB
PHP

<?php
namespace App\Http\Requests\Inventory;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdatePackagingItemRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, array<int, mixed>>
*/
public function rules(): array
{
return [
'packaging_material_id' => ['required', 'integer', 'exists:packaging_materials,id'],
'supplier_id' => ['nullable', 'integer', 'exists:suppliers,id'],
'name' => ['required', 'string', 'max:255'],
'category' => ['required', Rule::in(['packaging', 'shipping', 'label', 'shipping_office'])],
'weight_grams' => ['nullable', 'numeric', 'min:0'],
'min_stock_alert' => ['nullable', 'integer', 'min:0'],
'url' => ['nullable', 'url', 'max:500'],
'product_id' => ['nullable', 'integer', 'exists:products,id'],
'active' => ['sometimes', 'boolean'],
];
}
protected function prepareForValidation(): void
{
$this->merge([
'active' => $this->boolean('active'),
]);
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
if ($this->input($key) === '' || $this->input($key) === null) {
$this->merge([$key => null]);
}
}
}
}