Changed channel categories from DB-backed Category records to a backed PHP enum

This commit is contained in:
2026-05-18 06:55:03 +03:30
parent 295a408965
commit 59e4ae60da
20 changed files with 221 additions and 130 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Enums;
enum ChannelCategory: string
{
case Gaming = 'gaming';
case Music = 'music';
case TalkShows = 'talk-shows';
case Education = 'education';
case Creative = 'creative';
public function label(): string
{
return match ($this) {
self::Gaming => __('Gaming'),
self::Music => __('Music'),
self::TalkShows => __('Talk Shows'),
self::Education => __('Education'),
self::Creative => __('Creative'),
};
}
/**
* @return array{value: string, label: string}
*/
public function toOption(): array
{
return [
'value' => $this->value,
'label' => $this->label(),
];
}
/**
* @return list<array{value: string, label: string}>
*/
public static function options(): array
{
return array_map(
fn (self $category): array => $category->toOption(),
self::cases(),
);
}
}