refactor(formula): memindahkan otorisasi ke atas

This commit is contained in:
Yoga Pangestu 2025-12-09 20:44:10 +07:00
parent d02693ac64
commit f75c5c6300

View File

@ -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