F
Filamentā€¢2w ago
sohail

database notifications conditionally hide mark as unread/read button

I can add those buttons to a notification, but I only want it to be rendered if it is actually needed. If the notification is read. I don't know how I can inject a dependency in the closure, so I can conditionally hide it
->actions([
Action::make('markAsRead')
->button()
->markAsRead(),
Action::make('markAsUnread')
->button()
->markAsUnread(),
])
->actions([
Action::make('markAsRead')
->button()
->markAsRead(),
Action::make('markAsUnread')
->button()
->markAsUnread(),
])
4 Replies
SeƱor Nikola
SeƱor Nikolaā€¢2w ago
I had similar issue when tried to hide markAsRead, have not found solution yet.. Bump up šŸ™‚
toeknee
toekneeā€¢2w ago
->visible(fn($record) => !$record->read_at) If it's individual notification?
SeƱor Nikola
SeƱor Nikolaā€¢2w ago
Nah tried it first thing šŸ™‚ I get {"error":"An attempt was made to evaluate a closure for [Filament\Notifications\Actions\Action], but [$record] was unresolvable."}
toeknee
toekneeā€¢2w ago
->visible(fn($record) = !$livewire->ownerRecord->read_at)
->visible(fn($record) = !$livewire->ownerRecord->read_at)

Did you find this page helpful?