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:
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', ...
Jump to solution
3 Replies
Kenneth Sese
Kenneth Sese2y ago
Add default => 'your_color' to the end of your match statement.
Solution
Kenneth Sese
Kenneth Sese2y ago
You can also just use an array of colors and anything that isn't in the array gets the primary color:
->colors([
'gray' => 'draft',
'warning' => 'reviewing',
//everything else will become 'primary'
]),
->colors([
'gray' => 'draft',
'warning' => 'reviewing',
//everything else will become 'primary'
]),
Note the keys/colors are reversed in this example
Tieme
TiemeOP2y ago
Tahnks!

Did you find this page helpful?