'required|string|max:255|unique:parts', 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'manufacturer' => 'nullable|string|max:255', 'category' => 'nullable|string|max:255', 'cost_price' => 'required|numeric|min:0', 'sell_price' => 'required|numeric|min:0', 'quantity_on_hand' => 'required|integer|min:0', 'minimum_stock_level' => 'required|integer|min:0', 'maximum_stock_level' => 'required|integer|min:0', 'location' => 'nullable|string|max:255', 'supplier_id' => 'nullable|exists:suppliers,id', 'supplier_part_number' => 'nullable|string|max:255', 'lead_time_days' => 'nullable|integer|min:0', 'status' => 'required|in:active,inactive', 'barcode' => 'nullable|string|max:255', 'weight' => 'nullable|numeric|min:0', 'dimensions' => 'nullable|string|max:255', 'warranty_period' => 'nullable|integer|min:0', 'image' => 'nullable|image|max:2048', ]; public function save() { $this->validate(); $data = [ 'part_number' => $this->part_number, 'name' => $this->name, 'description' => $this->description, 'manufacturer' => $this->manufacturer, 'category' => $this->category, 'cost_price' => $this->cost_price, 'sell_price' => $this->sell_price, 'quantity_on_hand' => $this->quantity_on_hand, 'minimum_stock_level' => $this->minimum_stock_level, 'maximum_stock_level' => $this->maximum_stock_level, 'location' => $this->location, 'supplier_id' => $this->supplier_id ?: null, 'supplier_part_number' => $this->supplier_part_number, 'lead_time_days' => $this->lead_time_days, 'status' => $this->status, 'barcode' => $this->barcode, 'weight' => $this->weight, 'dimensions' => $this->dimensions, 'warranty_period' => $this->warranty_period, ]; // Handle image upload if ($this->image) { $data['image'] = $this->image->store('parts', 'public'); } Part::create($data); session()->flash('success', 'Part created successfully.'); return $this->redirect(route('inventory.parts.index')); } public function render() { $suppliers = Supplier::active()->orderBy('name')->get(); return view('livewire.inventory.parts.create', [ 'suppliers' => $suppliers, ]); } }