Custom Group Label

I am working on a Laravel Filament project and I have a problem with grouping a resource by blood group. I have an array that maps blood group ids to blood group names, like this:
$bloodGroups = [
    1 => 'A+',
    2 => 'B+',
    3 => 'AB+',
    4 => 'O+',
    5 => 'A-',
    6 => 'B-',
    7 => 'AB-',
    8 => 'O-'
];

I store the blood group id as an integer in the database, but I want to display the blood group name in the resource. However, when I use the groups method, it shows the id instead of the name, like this:
->groups([
    'required_on',
    'blood_group', // this shows the id, not the name
])

For example, it shows "Blood group: 1" instead of "Blood group: A+". How can I fix this?
image.png
Solution
If you put them in a table, then you can use:
https://filamentphp.com/docs/3.x/tables/grouping#setting-a-grouping-label

Else, remove the interfers and just create string array of groups and ensure the users enter as a string and not a number.
Was this page helpful?