F
Filamentβ€’8mo 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
Noorβ€’8mo ago
Can someone reply here ?
awcodes
awcodesβ€’8mo 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
Noorβ€’8mo ago
It shows each status in green only @awcodes
awcodes
awcodesβ€’8mo ago
did you remove ->colors() also might want to make sure you're getting the correct 'won' or 'lost' from the ternary
Noor
Noorβ€’8mo ago
Yes I did
awcodes
awcodesβ€’8mo 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β€’8mo ago
wouldn't created_at always be in the past though.
Noor
Noorβ€’8mo ago
$record->status->name may be I'm calling the record wrong its status.name its status name won lost taken etc
awcodes
awcodesβ€’8mo ago
i think it's because created at will always be in the past, and therefor will never evaluate to 'lost'
Noor
Noorβ€’8mo ago
oh ok
awcodes
awcodesβ€’8mo ago
if you swap 'won' and 'lost' you'll see that the color works. so it's just an issue with the logic. πŸ™‚
Noor
Noorβ€’8mo ago
ok thankyou πŸ™‚