How can I get this functionality on a TagsColumn

I'd like to be able to use formatting like this but on a TagsColumn. Using a TagsColumn works here with roles.name however the name comes straight out the database in snake case. Anyone know of a workaround?
Tables\Columns\BadgeColumn::make('roles.name')
->label('Roles')
->formatStateUsing(fn ($state): string => str($state)->headline())
->colors(['primary'])
Tables\Columns\BadgeColumn::make('roles.name')
->label('Roles')
->formatStateUsing(fn ($state): string => str($state)->headline())
->colors(['primary'])
10 Replies
Dennis Koch
Dennis Koch2y ago
Use a getStateUsing() instead to uppercase the values
backtrackjack
backtrackjackOP2y ago
life saver thanks!
Dennis Koch
Dennis Koch2y ago
You could also use an Attribute on Model level to get/set the value in the format you want
backtrackjack
backtrackjackOP2y ago
do you mean store roles as an attribute instead of a relation? I'm using the filament-shield plugin that makes a seperate model for roles.
Dennis Koch
Dennis Koch2y ago
No, use Laravel's Model Attributes (Mutator/Accessor) for transforming properties.
Dennis Koch
Dennis Koch2y ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
backtrackjack
backtrackjackOP2y ago
ah of course, this getStateUsing works well for now but I'll keep it in mind cheers! actually I'm intrigued. Because the Role model comes from a package, can I still create an accessor for it easily? maybe there's a vendor publish thing for it.
Dennis Koch
Dennis Koch2y ago
Create a Role in your app that extends Spatie's. Then set your model in the config.
Dennis Koch
Dennis Koch2y ago
I hope accessors work with the dot notation. I'm not 100% sure right now 🙈
Want results from more Discord servers?
Add your server