> */ 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]); } } } }