F
Filamentβ€’13mo ago
Noor

Color change by Task

Need a help with TextEntry::make('task.name') in infolist , where task is Won,Lost and Taken , how can I change there color by task and make it visible in view-infolist I tried this but did not worked \\
->getStateUsing(fn (Lead $record): string => $record->created_at?->isPast()? 'Won' : 'Lost') ->colors([ 'success' => 'Won', 'danger' => 'Lost' ]), \\
12 Replies
Noor
NoorOPβ€’13mo ago
Can someone reply here ?
awcodes
awcodesβ€’13mo ago
try this:
->color(function ($record) {
$status = $record->created_at?->isPast() ? 'won' : 'lost';
return match ($status) {
'won' => 'success',
'lost' => 'danger',
default => 'gray'
};
})
->color(function ($record) {
$status = $record->created_at?->isPast() ? 'won' : 'lost';
return match ($status) {
'won' => 'success',
'lost' => 'danger',
default => 'gray'
};
})
Noor
NoorOPβ€’13mo ago
It shows each status in green only @awcodes
awcodes
awcodesβ€’13mo ago
did you remove ->colors() also might want to make sure you're getting the correct 'won' or 'lost' from the ternary
Noor
NoorOPβ€’13mo ago
Yes I did
awcodes
awcodesβ€’13mo ago
maybe i'm misunderstanding what you are trying to do, but it's working for me in the demo
No description
No description
awcodes
awcodesβ€’13mo ago
wouldn't created_at always be in the past though.
Noor
NoorOPβ€’13mo ago
$record->status->name may be I'm calling the record wrong its status.name its status name won lost taken etc
awcodes
awcodesβ€’13mo ago
i think it's because created at will always be in the past, and therefor will never evaluate to 'lost'
Noor
NoorOPβ€’13mo ago
oh ok
awcodes
awcodesβ€’13mo ago
if you swap 'won' and 'lost' you'll see that the color works. so it's just an issue with the logic. πŸ™‚
Noor
NoorOPβ€’13mo ago
ok thankyou πŸ™‚
Want results from more Discord servers?
Add your server