Fix coupon enum formatting in Filament table
This commit is contained in:
@@ -40,7 +40,7 @@ class CouponsTable
|
||||
TextColumn::make('type')
|
||||
->label(__('Type'))
|
||||
->badge()
|
||||
->formatStateUsing(fn ($state) => Str::headline($state))
|
||||
->formatStateUsing(fn ($state) => static::formatEnumState($state))
|
||||
->sortable(),
|
||||
TextColumn::make('amount')
|
||||
->label(__('Amount'))
|
||||
@@ -59,7 +59,7 @@ class CouponsTable
|
||||
->label(__('Status'))
|
||||
->badge()
|
||||
->sortable()
|
||||
->formatStateUsing(fn ($state) => Str::headline($state)),
|
||||
->formatStateUsing(fn ($state) => static::formatEnumState($state)),
|
||||
TextColumn::make('starts_at')
|
||||
->label(__('Starts'))
|
||||
->date()
|
||||
@@ -151,4 +151,21 @@ class CouponsTable
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function formatEnumState(mixed $state): string
|
||||
{
|
||||
if ($state instanceof CouponType || $state instanceof CouponStatus) {
|
||||
return $state->label();
|
||||
}
|
||||
|
||||
if ($state instanceof \BackedEnum) {
|
||||
return Str::headline($state->value);
|
||||
}
|
||||
|
||||
if (is_string($state)) {
|
||||
return Str::headline($state);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user