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
Solution:Jump to 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:...
9 Replies
the desired result
Is priority an enum? If not you need to return an array of values and color keys.
Probably something like
->color(fn ($record) => $record->priority->color)
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...
Interesting! but priority.color returns #913434 , and ->color('#913434') doesn't work...
Aparently, colors could be only primary / secondary / warning / success / danger
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:
>color(fn ($record) => Color::hex($record->priority->color))
Great! that works!
What if the ticket BelongsToMany Priorities? How do I get the color of each priority?