From e11df20ea6fb1c6e9a40b172602f56e1765612a4 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 29 Apr 2026 21:48:02 +0700 Subject: [PATCH] feat: add options method to enums for OrderChannel, OrderStatus, PaymentMethod, and PriceType to streamline data retrieval --- app/Enums/OrderChannel.php | 8 ++++++++ app/Enums/OrderStatus.php | 8 ++++++++ app/Enums/PaymentMethod.php | 8 ++++++++ app/Enums/PriceType.php | 8 ++++++++ .../Controllers/Admin/Manage/OrderController.php | 16 ++++++++-------- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/Enums/OrderChannel.php b/app/Enums/OrderChannel.php index 671175b..60717bb 100644 --- a/app/Enums/OrderChannel.php +++ b/app/Enums/OrderChannel.php @@ -26,4 +26,12 @@ public function label(): string self::OTHER => 'Lainnya', }; } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } diff --git a/app/Enums/OrderStatus.php b/app/Enums/OrderStatus.php index 682f353..75998e5 100644 --- a/app/Enums/OrderStatus.php +++ b/app/Enums/OrderStatus.php @@ -20,4 +20,12 @@ public function label(): string self::CANCELLED => 'Gagal', }; } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } diff --git a/app/Enums/PaymentMethod.php b/app/Enums/PaymentMethod.php index 72c2df9..f8137e8 100644 --- a/app/Enums/PaymentMethod.php +++ b/app/Enums/PaymentMethod.php @@ -18,4 +18,12 @@ public function label(): string self::QRIS => 'QRIS', }; } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } diff --git a/app/Enums/PriceType.php b/app/Enums/PriceType.php index 409fcbd..60ca944 100644 --- a/app/Enums/PriceType.php +++ b/app/Enums/PriceType.php @@ -20,4 +20,12 @@ public function label(): string self::RETAIL => 'Retail', }; } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } diff --git a/app/Http/Controllers/Admin/Manage/OrderController.php b/app/Http/Controllers/Admin/Manage/OrderController.php index 2067cd5..7ba85ba 100644 --- a/app/Http/Controllers/Admin/Manage/OrderController.php +++ b/app/Http/Controllers/Admin/Manage/OrderController.php @@ -36,10 +36,10 @@ public function create(): Response ->whereNull('order_id') ->latest() ->get(), - 'orderStatus' => collect(OrderStatus::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'orderChannels' => collect(OrderChannel::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'paymentMethods' => collect(PaymentMethod::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'priceTypes' => collect(PriceType::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), + 'orderStatus' => OrderStatus::options(), + 'orderChannels' => OrderChannel::options(), + 'paymentMethods' => PaymentMethod::options(), + 'priceTypes' => PriceType::options(), ]); } @@ -108,10 +108,10 @@ public function edit(Order $order): Response return Inertia::render('admin/manage/order/edit', [ 'order' => $order, 'products' => Product::with(['prices', 'categories'])->active()->get(), - 'orderStatus' => collect(OrderStatus::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'orderChannels' => collect(OrderChannel::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'paymentMethods' => collect(PaymentMethod::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), - 'priceTypes' => collect(PriceType::cases())->map(fn ($case) => ['value' => $case->value, 'label' => $case->label()]), + 'orderStatus' => OrderStatus::options(), + 'orderChannels' => OrderChannel::options(), + 'paymentMethods' => PaymentMethod::options(), + 'priceTypes' => PriceType::options(), ]); }