From 0c7ab27a785fa5d298617523158cbf06c6192062 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 10 Dec 2025 14:19:11 +0700 Subject: [PATCH] refactor(brand): menambahkan return type --- .../Datatable/Studio/Catalog/BrandsTable.php | 1 - .../Forms/Studio/Catalog/BrandForm.php | 14 +++---- app/Livewire/Studio/Catalog/Brand.php | 41 ++++++++++--------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/app/Livewire/Datatable/Studio/Catalog/BrandsTable.php b/app/Livewire/Datatable/Studio/Catalog/BrandsTable.php index 3232fc4..f458480 100644 --- a/app/Livewire/Datatable/Studio/Catalog/BrandsTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/BrandsTable.php @@ -87,7 +87,6 @@ public function columns(): array if (auth()->user()->can('delete brand')) { $actions .= view('components.actions.table.delete', [ 'id' => $row->hash, - 'deleteRoute' => route('studio.catalog.brand.delete', $row->hash), ])->render(); } diff --git a/app/Livewire/Forms/Studio/Catalog/BrandForm.php b/app/Livewire/Forms/Studio/Catalog/BrandForm.php index a0567c5..b7f9d73 100644 --- a/app/Livewire/Forms/Studio/Catalog/BrandForm.php +++ b/app/Livewire/Forms/Studio/Catalog/BrandForm.php @@ -22,7 +22,7 @@ public function rules(): array { return [ 'name' => ['required', 'max:20', Rule::unique('brands', 'name')->whereNull('deleted_at')->ignore($this->brand)], - 'image' => ['nullable', 'array'], + 'image' => 'array', ]; } @@ -34,7 +34,7 @@ public function validationAttributes(): array ]; } - public function setBrand(Brand $brand) + public function setBrand(Brand $brand): void { $this->brand = $brand; @@ -43,7 +43,7 @@ public function setBrand(Brand $brand) $this->image = $this->mapMediaCollection($brand->getMedia('image')); } - public function store() + public function store(): void { $this->validate(); @@ -57,7 +57,7 @@ public function store() }); } - public function update() + public function update(): void { $this->validate(); @@ -71,7 +71,7 @@ public function update() }); } - public function delete() + public function delete(): void { $this->brand->delete(); @@ -83,7 +83,7 @@ public function delete() }); } - public function sortOrder(string $direction) + public function sortOrder(string $direction): void { if (in_array($direction, ['up', 'down'])) { $swap = null; @@ -112,7 +112,7 @@ public function sortOrder(string $direction) } } - protected function normalizeSortOrder() + protected function normalizeSortOrder(): void { $categories = Brand::orderBy('sort_order')->get(); foreach ($categories as $index => $brand) { diff --git a/app/Livewire/Studio/Catalog/Brand.php b/app/Livewire/Studio/Catalog/Brand.php index 5199ee6..69197b7 100644 --- a/app/Livewire/Studio/Catalog/Brand.php +++ b/app/Livewire/Studio/Catalog/Brand.php @@ -11,6 +11,7 @@ use App\Traits\WithToast; use App\Traits\WithUpdatedData; use Flux\Flux; +use Illuminate\Contracts\View\View; use Livewire\Attributes\On; use Livewire\Attributes\Title; use Livewire\Component; @@ -26,21 +27,7 @@ class Brand extends Component public string $modalTitle = ''; - #[On('modal:open')] - public function openModal(string $method, string $modalTitle, ?string $id = null) - { - $this->resetValidation(); - $this->resetErrorBag(); - - $this->method = $method; - $this->modalTitle = $modalTitle; - - if ($id) { - $this->form->setBrand(BrandModel::byHashOrFail($id)); - } - } - - public function create() + public function create(): void { $this->canOrAbort('create brand'); @@ -53,7 +40,7 @@ public function create() Flux::modals()->close(); } - public function update() + public function update(): void { $this->canOrAbort('update brand'); @@ -66,8 +53,10 @@ public function update() Flux::modals()->close(); } - public function delete(BrandModel $brand) + public function delete(BrandModel $brand): void { + $this->canOrAbort('delete brand'); + $this->form->brand = $brand; $this->form->delete(); @@ -80,7 +69,7 @@ public function delete(BrandModel $brand) } #[On('fn:sortOrder')] - public function sortOrder(BrandModel $brand, string $direction) + public function sortOrder(BrandModel $brand, string $direction): void { $this->canOrAbort('update brand'); @@ -91,7 +80,21 @@ public function sortOrder(BrandModel $brand, string $direction) $this->dispatch('refreshDatatable'); } - public function render() + #[On('modal:open')] + public function openModal(string $method, string $modalTitle, ?string $id = null): void + { + $this->resetValidation(); + $this->resetErrorBag(); + + $this->method = $method; + $this->modalTitle = $modalTitle; + + if ($id) { + $this->form->setBrand(BrandModel::byHashOrFail($id)); + } + } + + public function render(): View { return view('livewire.studio.catalog.brands', [ 'pageTitle' => 'Merek',