FilamentF
Filament7mo ago
FabioB

Tooltip on Enums?

Hi!
Trying to add a tooltip to a (table) TextColumn.

  1. My Enum looks like this:
<?php

namespace App\Enums;

use ...
use ...
use ...

enum TicketPriority: string implements HasLabel, HasColor, HasIcon
{
case Low = 'low';
case Medium = 'medium';
case High = 'high';
case Urgent = 'urgent';

.....
public function getTooltip(): ?string
{
return match ($this) {
self::Low => ('Longer description 1 here ....'),
self::Medium =>
('Longer description 2 here ....'),
self::High => ('Longer description 3 here ....'),
self::Urgent =>
('Longer description 4 here ....'),
};
}
....


  1. On my resource im trying to get:... IconColumn::make('priority') ->label('') //-narrower column ->icon(fn($state) => $state->getIcon()) //-Picks and shows the icon ->size(IconColumnSize::Medium) ->tooltip(fn($state) => $state->getTooltip()),...
  2. I get the following error:
Call to a member function getTooltip() on null . The same for getLabel() ....

  1. However, if I do something like this:...IconColumn::make('priority') ->label('') ->icon(fn($state) => $state->getIcon()) ->size(IconColumnSize::Medium) ->tooltip(fn($state) => dd($state->getTooltip())), <------------ ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ...
  2. I actually get: "Longer description 1 here ...." // app/Filament/Resources/TicketResource.php:116
  3. What am I missing??Thanks!!!!
Solution
The error happens because $state is null in some rows
IconColumn::make('priority')
    ->label('')
    ->icon(fn($state) => $state?->getIcon())
    ->size(IconColumnSize::Medium)
   ->tooltip(fn($state) => $state?->getTooltip())
Was this page helpful?