feat: add options method to enums for OrderChannel, OrderStatus, PaymentMethod, and PriceType to streamline data retrieval

This commit is contained in:
Yoga Pangestu 2026-04-29 21:48:02 +07:00
parent 00a9eb96d0
commit e11df20ea6
5 changed files with 40 additions and 8 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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(),
]);
}