F
Filament2y ago
dyo

closure in badgeColumn colors

I want to set the color success when the column value contains string of 'online'. the value of column status is generated from api. i tried below code, but i got error because of $record data is null..
BadgeColumn::make('status')
->formatStateUsing(fn ($record) => $this->getStatus($record->license))
->colors([
'warning' => static fn ($record): bool => strpos($this->getStatus($record->license), 'logout') !== false,
'success' => static fn ($record): bool => strpos($this->getStatus($record->license), 'online') !== false,
]),
BadgeColumn::make('status')
->formatStateUsing(fn ($record) => $this->getStatus($record->license))
->colors([
'warning' => static fn ($record): bool => strpos($this->getStatus($record->license), 'logout') !== false,
'success' => static fn ($record): bool => strpos($this->getStatus($record->license), 'online') !== false,
]),
what should i do?
4 Replies
Iliyas M
Iliyas M2y ago
Try this
BadgeColumn::make('status')
->getStateUsing(fn($record) => $this->getStatus($record->license))
->color(function($state) {
if(Str::contains($state, "online")) {
return 'success';
}
return 'warning';
}),
BadgeColumn::make('status')
->getStateUsing(fn($record) => $this->getStatus($record->license))
->color(function($state) {
if(Str::contains($state, "online")) {
return 'success';
}
return 'warning';
}),
dyo
dyoOP2y ago
it's all return in else..
Vp
Vp2y ago
You can access record like this
->colors(function ($record) {
dd($record);
}),
->colors(function ($record) {
dd($record);
}),
dyo
dyoOP2y ago
found out! silly me, i misstyped the string 'online', which is should be 'Online'
Want results from more Discord servers?
Add your server