sizes = Bottle::withoutGlobalScope('orderedBySize') ->distinct() ->orderBy('size') ->pluck('size') ->toArray(); } public function create(): void { $this->canOrAbort('create formula'); if (FormulaModel::where('quality', $this->form->quality)->where('size', $this->form->size)->exists()) { $this->toast('Rumus dengan kualitas dan ukuran tersebut sudah ada.', 'Info', 'warning'); return; } $this->form->store(); $this->toast('Rumus berhasil ditambahkan.'); Flux::modals()->close(); } public function update(): void { $this->canOrAbort('update formula'); $exists = FormulaModel::where('quality', $this->form->quality) ->where('size', $this->form->size) ->where('id', '!=', $this->form->formula->id) ->exists(); if ($exists) { $this->toast('Rumus dengan kualitas dan ukuran tersebut sudah ada.', 'Info', 'warning'); return; } $this->form->update(); $this->toast('Rumus berhasil diperbarui.'); Flux::modals()->close(); } public function delete(FormulaModel $formula): void { $this->canOrAbort('delete formula'); $formula->delete(); $this->toast('Rumus berhasil dihapus.'); Flux::modals()->close(); } #[On('modal:open')] public function openModal(string $method, string $modalTitle, ?string $id = null): void { $this->resetValidation(); $this->resetErrorBag(); $this->method = $method; $this->modalTitle = $modalTitle; $id && $this->form->setFormula(FormulaModel::byHashOrFail($id)); } public function render(): View { $formulas = FormulaModel::orderBy('size') ->get() ->groupBy('size') ->map( fn ($items) => $items ->map(fn ($item) => [ 'hash' => $item->hash, 'quality' => $item->quality, 'volume' => $item->volume, ]) ->sortBy('volume') ->values() ->toArray() ) ->toArray(); return view('livewire.studio.master.formulas', [ 'pageTitle' => 'Rumus', 'formulas' => $formulas, ]); } }