F
Filament3mo ago
Crylar

Conditional component builder

Hello guys, I was wondering if there is a better way to write this:
Tables\Columns\TextColumn::make('starts_at')
->label('Status')
->alignCenter()
->badge()
->color(
fn (PreOrderInvitation $record) => $record->starts_at->isFuture()
? Color::Orange
: Color::Green
)
->icon(fn (PreOrderInvitation $record) => $record->starts_at->isFuture() ? 'gmdi-schedule-o' : false)
->tooltip(fn (PreOrderInvitation $record) => $record->starts_at->format('Y-m-d H:i'))
->formatStateUsing(fn (PreOrderInvitation $record) => $record->starts_at->isFuture() ? 'scheduled' : 'sent'),
Tables\Columns\TextColumn::make('starts_at')
->label('Status')
->alignCenter()
->badge()
->color(
fn (PreOrderInvitation $record) => $record->starts_at->isFuture()
? Color::Orange
: Color::Green
)
->icon(fn (PreOrderInvitation $record) => $record->starts_at->isFuture() ? 'gmdi-schedule-o' : false)
->tooltip(fn (PreOrderInvitation $record) => $record->starts_at->format('Y-m-d H:i'))
->formatStateUsing(fn (PreOrderInvitation $record) => $record->starts_at->isFuture() ? 'scheduled' : 'sent'),
I do sometimes find myself repeating same code when I need to conditionally define particular values... is there a better way, where I could just check for a single condition and based on this set needed parameters.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server