© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
Askancy

Set text on the badge according to the value

I have this badge that takes from id_topic the topic number on the forum where comments are open.
If id_topic is 0 then comments are closed, if it contains an id above 0 then comments are open.
I have tried this, but inside the badge it always returns me the id of id_topic and not the words "open" or "close"

TextColumn::make('id_topic')
    ->badge(fn ($state): string => $state > 0 ? 'Open' : 'Close')
    ->color(fn ($state): string => $state > 0 ? 'success' : 'gray')
    ->label('Comments'),
TextColumn::make('id_topic')
    ->badge(fn ($state): string => $state > 0 ? 'Open' : 'Close')
    ->color(fn ($state): string => $state > 0 ? 'success' : 'gray')
    ->label('Comments'),
Solution
That's why, you need formatStateUsing not badge:

https://filamentphp.com/docs/2.x/tables/columns/text#custom-formatting
Text column - Table Builder - Filament
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is it possible to hide Badge based on the value?
FilamentFFilament / ❓┊help
3y ago
How to combine text and badge?
FilamentFFilament / ❓┊help
2y ago
Updating value of Navigation Badge
FilamentFFilament / ❓┊help
2y ago
Text Column Badge Color based on Pivot attribute
FilamentFFilament / ❓┊help
2y ago