Laravel filament: Is there any way to mutate group data column default value in table?

30 Views Asked by At

I have a user model. I grouped data by user_type, now grouped data shows with default value of the column. How can it be formatted?

enter image description here

Is there any way to show user_type field formatted value on group in table?

1

There are 1 best solutions below

0
ManojKiran On

As suggested in the docs you can customize group title by using getTitleFromRecordUsing

public function table(Table $table): Table
{
    return $table
        ->groups([
            Group::make('user_type')
                ->getTitleFromRecordUsing(function ($record) {
                    $value = (int) $record->user_type;
                    return match ($value) {
                        1 => "User",
                        2 => "Admin",
                        default => "Unknown"
                    };
                }),
        ]);
}