badge color from color field

Hi. My APP has a "priority" model with a name and a 'color' field. My "ticket" model belongsTo a priority, so I need to show the badge in the corresponding color. Any example? Thanks
No description
Solution:
When you have a hexadecimal value you can use: Color::hex(); https://filamentphp.com/docs/3.x/support/colors#generating-a-custom-color-from-a-hex-code To help you to the end result:...
Jump to solution
9 Replies
PabloZagni
PabloZagniOP4mo ago
No description
PabloZagni
PabloZagniOP4mo ago
the desired result
No description
awcodes
awcodes4mo ago
Is priority an enum? If not you need to return an array of values and color keys.
Dennis Koch
Dennis Koch4mo ago
Probably something like ->color(fn ($record) => $record->priority->color)
PabloZagni
PabloZagniOP4mo ago
Priority is a model, some records in the database, with ID, NAME and COLOR fields. I let the user choose the priority color. So.. I want to show the badges in that color...
No description
PabloZagni
PabloZagniOP4mo ago
Interesting! but priority.color returns #913434 , and ->color('#913434') doesn't work... Aparently, colors could be only primary / secondary / warning / success / danger
Solution
Keika
Keika4mo ago
When you have a hexadecimal value you can use: Color::hex(); https://filamentphp.com/docs/3.x/support/colors#generating-a-custom-color-from-a-hex-code To help you to the end result: >color(fn ($record) => Color::hex($record->priority->color))
PabloZagni
PabloZagniOP4mo ago
Great! that works!
No description
No description
PabloZagni
PabloZagniOP4mo ago
What if the ticket BelongsToMany Priorities? How do I get the color of each priority?
Want results from more Discord servers?
Add your server