badge default color
Hi All,
I am implementing following Badge With Color : https://filamentphp.com/docs/3.x/tables/columns/text#displaying-as-a-badge
TextColumn::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'draft' => 'gray',
'reviewing' => 'warning',
'published' => 'success',
'rejected' => 'danger',
})
Is there anyway that i can set a default color if state does not exists?
Now it will trohw a exception / error
UnhandledMatchError
Unhandled match case 'created'
Thanks!
Solution:Jump to solution
You can also just use an array of colors and anything that isn't in the array gets the primary color:
```php
->colors([
'gray' => 'draft',
'warning' => 'reviewing', ...
3 Replies
Add
default => 'your_color'
to the end of your match statement.Solution
You can also just use an array of colors and anything that isn't in the array gets the primary color:
Note the keys/colors are reversed in this example
Tahnks!