phplaravellaravel-filamentfilamentphp

How to colorize summarizers and/or their output?


I am using summaries to display the total amount to pay:

TextColumn::make('price')
    ->summarize(Sum::make())

I would like to colorize the default "Sum" label and its output because this is important information to highlight for the user.

How to achieve this?


Solution

  • you may use formatStateUsing() method on the Sum object to style the output like below example snippet

    use ****\TextColumn;
    use ***\Sum;
    
    TextColumn::make('price')
        ->summarize(
            Sum::make()
                ->formatStateUsing(fn ($state) => '<span style="color: red; font-weight: bold;">$' . number_format($state, 2) . '</span>')
                ->html(), // NOTE: you should allow HTML rendering
        )