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?
10 Replies
Use a
getStateUsing()
instead to uppercase the valueslife saver thanks!
You could also use an Attribute on Model level to get/set the value in the format you want
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.
No, use Laravel's Model Attributes (Mutator/Accessor) for transforming properties.
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.
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.
Create a Role in your app that extends Spatie's. Then set your model in the config.
I hope accessors work with the dot notation. I'm not 100% sure right now 🙈