F
Filamentβ€’12mo ago
Pablo Torres

In a table display custom text when column is null. Works on v2 but not on v3.

This works on v2 but not on v3, any suggestions, please? On Filament v2 When the column 'marked_ready_at' does not yet have a date (is null) it shows 'Not yet'. Otherwise, it shows the date in a human-friendly way. On Filament v3 It doesn't work. Model
protected $casts = [
'marked_ready_at' => 'datetime',
];
protected $casts = [
'marked_ready_at' => 'datetime',
];
Filament resource
Tables\Columns\TextColumn::make('marked_ready_at')
->dateTime('M j, y')
->description(fn (Booking $record): string => $record->marked_ready_at?->since() ?? 'Not yet')
Tables\Columns\TextColumn::make('marked_ready_at')
->dateTime('M j, y')
->description(fn (Booking $record): string => $record->marked_ready_at?->since() ?? 'Not yet')
Does anyone have the update or perhaps a better approach to achieve it? PHP v8.2 Thank you.
3 Replies
Lara Zeus
Lara Zeusβ€’12mo ago
you can use ->default('Not yet')
Pablo Torres
Pablo TorresOPβ€’12mo ago
Hi, Implementing '->default('Not yet')' I get the following error: Could not parse 'Not yet': Failed to parse time string (Not yet) at position 0 (N): The timezone could not be found in the database
Lara Zeus
Lara Zeusβ€’12mo ago
so I guess you have to ditch the datetime() and do it like this
Tables\Columns\TextColumn::make('email_verified_at')
//->dateTime('M j, y')
->default('not yet')
->formatStateUsing(fn(User $record)=> $record->email_verified_at ? $record->email_verified_at->format('M j, y') : 'Not yet')
->description(fn (User $record): string => $record->email_verified_at?->since() ?? 'Not yet'),
Tables\Columns\TextColumn::make('email_verified_at')
//->dateTime('M j, y')
->default('not yet')
->formatStateUsing(fn(User $record)=> $record->email_verified_at ? $record->email_verified_at->format('M j, y') : 'Not yet')
->description(fn (User $record): string => $record->email_verified_at?->since() ?? 'Not yet'),
dont like too, πŸ™‚ maybe use accessor?!
Want results from more Discord servers?
Add your server