by Adam Weston
Badgeable Column allows you to add badges to columns that appear at the end of the column's value.
You can install the package via composer:
composer require awcodes/filament-badgeable-column
Optionally, you can publish the views, translations and assets using
php artisan vendor:publish --tag="filament-badgeable-column-views"php artisan vendor:publish --tag="filament-badgeable-column-translations"php artisan vendor:publish --tag="filament-badgeable-column-assets"
use Awcodes\FilamentBadgeableColumn\Components\Badge;use Awcodes\FilamentBadgeableColumn\Components\BadgeField;use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn; return $table ->columns([ BadgeableColumn::make('title') ->badges([ Badge::make('front_page') ->label('Front Page') ->color('success') ->visible(fn ($record): bool => $record->front_page), Badge::make('front_page_custom_color') ->label('#bada55') ->color('#bada55') ->visible(fn ($record): bool => $record->front_page), Badge::make('trashed') ->label('Trashed') ->color('danger') ->visible(fn ($record): bool => $record->deleted_at ?? false), BadgeField::make('status') ->options([ 'Draft' => 'Draft', 'Review' => 'In Review', 'Published' => 'Published' ]) ->colors([ 'gray' => 'Draft', 'warning' => 'Review', 'success' => 'Published', ]) ->visible(fn ($record): bool => $record->status !== Status::Published->name) ]) ->searchable() ->sortable(), ]);
This is similar to the Badgeable Column
except it allows you to use an
array of data to simply output badges in the column. You field must return
an array from the record.
use Awcodes\FilamentBadgeableColumn\Components\BadgeableTagsColumn; BadgeableTagsColumn::make('tags') ->colors([ 'gray', 'primary' => 'Dan', '#bada55' => 'Zep', 'warning' => 'Dennis', '#0e7490' => 'Ryan', ]),
If you prefer to have a more "square" shape you can use the asPills()
method to set the shape of the badges. The default is that each badge
will be a pill shape.
BadgeableTagsColumn::make('tags') ->asPills(false) ->colors([ 'gray', 'primary' => 'Dan', '#bada55' => 'Zep', 'warning' => 'Dennis', '#0e7490' => 'Ryan', ]),