F
Filamentβ€’16mo ago
rubendn

Icon Visibility on Text Column depending on record value

I have a Text Column with a modal where I'm showing an Icon and Text. I'm able to hide the text depending on the status of the $record->StatusID from the model by using formatStateUsing() but the icon still shows. Is there a way to make the display of the icon conditional? See code below.
Tables\Columns\TextColumn::make('tracking')
->action(Action::make('updateShipping')
->action(function (Model $record, array $data): void {
$record->ConfirmationNumber = $data['ConfirmationNumber'];
$record->StatusID = 3;
$record->save();
\Mail::to($record->EmailAddress)->send(new \App\Mail\TrackingNumber($record));
})
->form([
TextInput::make('ConfirmationNumber')
->label('Delivery Confirmation #')
->required(),
])
->label(fn (Model $record) => "Order#: {$record->OrderID} - {$record->FirstName} {$record->LastName}")
)
->icon('heroicon-o-truck')
->label('Tracking')
->alignCenter()
->formatStateUsing(function (Model $record): string {
return $record->StatusID == 5 ? 'SHIP' : '';
}),
Tables\Columns\TextColumn::make('tracking')
->action(Action::make('updateShipping')
->action(function (Model $record, array $data): void {
$record->ConfirmationNumber = $data['ConfirmationNumber'];
$record->StatusID = 3;
$record->save();
\Mail::to($record->EmailAddress)->send(new \App\Mail\TrackingNumber($record));
})
->form([
TextInput::make('ConfirmationNumber')
->label('Delivery Confirmation #')
->required(),
])
->label(fn (Model $record) => "Order#: {$record->OrderID} - {$record->FirstName} {$record->LastName}")
)
->icon('heroicon-o-truck')
->label('Tracking')
->alignCenter()
->formatStateUsing(function (Model $record): string {
return $record->StatusID == 5 ? 'SHIP' : '';
}),
Thank you!
Solution:
sure, use a closure customization as well:
->icon(static fn (Model $record): string|null => $record->statusID === 5 ? 'heroicon-o-truck' : null)
->icon(static fn (Model $record): string|null => $record->statusID === 5 ? 'heroicon-o-truck' : null)
...
Jump to solution
5 Replies
Solution
josef
josefβ€’16mo ago
sure, use a closure customization as well:
->icon(static fn (Model $record): string|null => $record->statusID === 5 ? 'heroicon-o-truck' : null)
->icon(static fn (Model $record): string|null => $record->statusID === 5 ? 'heroicon-o-truck' : null)
josef
josefβ€’16mo ago
Wherever you can give a Field/Component's method a Closure, you can do this
dansing
dansingβ€’16mo ago
and just for additional, I recommend to add your status value in your related model for readability πŸ™‚ e.g const ORDER_STATUS_PAID = 4; const ORDER_STATUS_SHIPPED = 5; const ORDER_STATUS_DELIVERED = 6;
josef
josefβ€’16mo ago
Or use an Enum
rubendn
rubendnOPβ€’16mo ago
Thank you. That worked.
Want results from more Discord servers?
Add your server