warehouses = Warehouse::orderBy('name')->pluck('name', 'id')->toArray(); $this->outlets = auth()->user()->outlets->pluck('name', 'id')->toArray(); $this->restockItems = $this->loadRestockItems(); } public function updated($property, $value): void { if ($property === 'form.warehouse_id' || $property === 'form.outlet_id') { $this->loadCreateItems(); } } private function loadCreateItems(): void { $this->reset(['perfumes', 'products', 'bottles']); $this->form->reset( 'perfume_id', 'quantity_perfume', 'product_id', 'quantity_product', 'bottle_id', 'quantity_bottle' ); if (! $this->form->warehouse_id || ! $this->form->outlet_id) { return; } $warehouse = Warehouse::find($this->form->warehouse_id); if (! $warehouse) { return; } $this->perfumes = $warehouse->perfumes() ->wherePivot('stock', '>', 0) ->get() ->pluck('name', 'id') ->toArray(); $this->products = $warehouse->products() ->wherePivot('stock', '>', 0) ->get() ->pluck('name', 'id') ->toArray(); $this->bottles = $warehouse->bottles() ->wherePivot('stock', '>', 0) ->get() ->pluck('display_name', 'id') ->toArray(); } public function save(): void { $this->canOrAbort('create restock'); if ($this->restockItems->isEmpty()) { $this->toast('Keranjang restock tidak boleh kosong.', 'Gagal', 'danger'); return; } try { $this->form->store(); } catch (ValidationException $e) { throw $e; } catch (\Exception $e) { $this->toast($e->getMessage(), 'Gagal', 'danger'); return; } $this->redirectRoute('studio.stock.restock.index', [ 'notification' => 'Restock berhasil diproses.', ], navigate: true); } public function render(): View { return view('livewire.studio.stock.restock.form', [ 'pageTitle' => 'Tambah Restock Toko', ]); } }