47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Inventory;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StorePackagingItemRequest 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'])],
|
|
'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'),
|
|
'category' => trim((string) $this->input('category')),
|
|
'weight_grams' => $this->filled('weight_grams') ? reFormatNumber($this->input('weight_grams')) : null,
|
|
]);
|
|
|
|
foreach (['supplier_id', 'product_id', 'min_stock_alert'] as $key) {
|
|
if ($this->input($key) === '' || $this->input($key) === null) {
|
|
$this->merge([$key => null]);
|
|
}
|
|
}
|
|
}
|
|
}
|