F
Filament5mo 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 ....'), }; } .... 2. 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()), ... 3. I get the following error: Call to a member function getTooltip() on null . The same for getLabel() .... 4. 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())), <------------ ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ ... 5. I actually get: "Longer description 1 here ...." // app/Filament/Resources/TicketResource.php:116 6. 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())...
Jump to solution
3 Replies
dvarilek
dvarilek5mo ago
There is probably some record in your table being rendered that has no priority set at all, hence the error. Simply just use null safe operators
IconColumn::make('priority')
->icon(fn($state) => $state?->getIcon())
->tooltip(fn($state) => $state?->getTooltip())
IconColumn::make('priority')
->icon(fn($state) => $state?->getIcon())
->tooltip(fn($state) => $state?->getTooltip())
Solution
Radit
Radit5mo ago
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())
IconColumn::make('priority')
->label('')
->icon(fn($state) => $state?->getIcon())
->size(IconColumnSize::Medium)
->tooltip(fn($state) => $state?->getTooltip())
FabioB
FabioBOP5mo ago
Thank you both. That solved the issue.

Did you find this page helpful?