From f75c5c6300ff36aa8597d7126af30e992b83c6fe Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 9 Dec 2025 20:44:10 +0700 Subject: [PATCH] refactor(formula): memindahkan otorisasi ke atas --- app/Livewire/Studio/Master/Formula.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Studio/Master/Formula.php b/app/Livewire/Studio/Master/Formula.php index 204ed23..7c9e9b1 100644 --- a/app/Livewire/Studio/Master/Formula.php +++ b/app/Livewire/Studio/Master/Formula.php @@ -69,14 +69,14 @@ public function openModal(string $method, string $modalTitle, ?string $id = null 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->canOrAbort('create formula'); - $formula = $this->form->store(); // push new formula to collection @@ -115,6 +115,8 @@ public function create(): void 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) @@ -126,8 +128,6 @@ public function update(): void return; } - $this->canOrAbort('update formula'); - $formula = $this->form->update(); // update collection formulas