TextInput with visibleOn() and visible()

I want to show published date on edit page only and only if the published date is not null, I am doing like following but I am getting error on create page.
App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\ModelName, null given
App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\ModelName, null given
TextInput::make('published_at')
->disabled()
->formatStateUsing(fn($record) => $record?->published_at?->format('M d, Y - h:i:s A'))
->visibleOn('edit')
->visible(fn(ModelName $record): bool => (bool)$record->published_at),
TextInput::make('published_at')
->disabled()
->formatStateUsing(fn($record) => $record?->published_at?->format('M d, Y - h:i:s A'))
->visibleOn('edit')
->visible(fn(ModelName $record): bool => (bool)$record->published_at),
3 Replies
ZedoX
ZedoX2y ago
You cannot used both, together, ->visibleOn() uses ->visible() under the hood
Dan Harrin
Dan Harrin2y ago
you should check $context === ‘edit’ inside the callback or just make $record nullable
Darpan
DarpanOP2y ago
Thanks!
Want results from more Discord servers?
Add your server