awcodes/filament-badgeable-column
Install the package:
composer require awcodes/filament-badgeable-column
Ensure your Filament version matches the compatibility table (e.g., 4.x for Filament 5.x).
Publish the config (optional):
php artisan vendor:publish --provider="Awcodes\FilamentBadgeableColumn\FilamentBadgeableColumnServiceProvider" --tag="config"
Customize badge styles, colors, or default behavior in config/filament-badgeable-column.php.
First use case:
Add a BadgeableColumn to a Filament table:
use Awcodes\FilamentBadgeableColumn\Columns\BadgeableColumn;
BadgeableColumn::make('status')
->badge('active')
->badge('pending', color: 'warning')
->badge('archived', color: 'gray'),
Place this in your table’s columns() method.
config/filament-badgeable-column.php for default badge styles/colors.src/Columns/BadgeableColumn.php for advanced customization hooks.Basic Badge Display:
BadgeableColumn::make('user_type')
->badge('admin')
->badge('editor', color: 'info')
->badge('guest', color: 'gray'),
->badge(fn ($record) => $record->is_premium ? 'premium' : 'basic')
Conditional Badges:
BadgeableColumn::make('status')
->badge('active', show: fn ($record) => $record->is_active)
->badge('inactive', show: fn ($record) => !$record->is_active),
Custom Badge Styling:
->badge('urgent', color: 'red.500', icon: 'heroicon-o-bell-slash')
Integration with Filament Actions:
Actions\Action for contextual buttons:
Table::make()
->columns([
BadgeableColumn::make('priority')
->badge('high')
->badge('low'),
])
->actions([
Action::make('escalate')
->visible(fn ($record) => $record->priority === 'high'),
]),
Reusable Badge Sets:
protected function getStatusBadges(): array {
return [
'published' => 'success',
'draft' => 'warning',
'archived' => 'gray',
];
}
Badge Icons:
->badge('verified', icon: 'heroicon-o-check-circle')
Badge Tooltips:
->badge('pro', tooltip: 'Premium features unlocked')
Badge Groups:
badge() calls for multi-value fields (e.g., tags):
BadgeableColumn::make('tags')
->badge(fn ($record) => $record->tags->first()?->name)
->badge(fn ($record) => $record->tags->last()?->name),
Dynamic Badge Content:
->badge(fn ($record) => "Level {$record->experience_level}")
Override Default Rendering: Extend the column class to modify badge HTML:
use Awcodes\FilamentBadgeableColumn\Columns\BadgeableColumn;
class CustomBadgeColumn extends BadgeableColumn {
protected function getBadgeHtml(string $value): string {
return '<span class="custom-badge">'.$value.'</span>';
}
}
Version Mismatch:
Class 'Awcodes\FilamentBadgeableColumn\Columns\BadgeableColumn' not found.awcodes/filament-badgeable-column and filament/filament versions align (e.g., 4.x for Filament 5.x).Badge Overlap:
->badge(..., stack: false) or adjust CSS:
.filament-tables-column-badge {
display: block;
}
Closure Performance:
badge() closures for large datasets.Config Overrides:
color overrides take precedence over config defaults.config('filament-badgeable-column.defaults') for global defaults.Dynamic Data Changes:
Table::make()->refresh() in actions.Inspect Badge Rendering:
->badge('debug', color: 'primary') to verify column rendering.Check for Cached Views:
php artisan view:clear
Log Badge Values:
->badge(fn ($record) => {
\Log::debug('Record:', [$record->toArray()]);
return $record->status;
})
Custom Badge Types:
Badge class to add new styles or behaviors:
class CustomBadge extends \Awcodes\FilamentBadgeableColumn\Badge {
public static function make(string $value): static {
return new static($value, 'custom');
}
}
Badge Events:
BadgeRendered):
event(new \Awcodes\FilamentBadgeableColumn\Events\BadgeRendered($badge, $column));
Localization:
'filament-badgeable-column' => [
'badges' => [
'active' => 'Active Status',
],
],
Testing:
$this->assertTableHasColumnInRow('status', 'active', 'badge');
Consistent Naming:
user-role) to avoid CSS conflicts.Dark Mode Support:
->badge('active', color: 'green.500 dark:green.400')
Accessibility:
aria-label for screen readers:
->badge('verified', ariaLabel: 'Account verified')
Performance:
->badge(..., lazy: true) to defer rendering.Documentation:
/**
* @return string[] Possible badge values: 'active', 'pending', 'archived'
*/
public function getStatusBadges(): array { ... }
How can I help you explore Laravel packages today?