F
Filament8mo ago
Wim

Don't show Actions for Database notifications that are marked as read

I have the following database notification:
Notification::make()
->title('Product published')
->body('Product published successfully')
->actions([
Action::make('Mark As Read')
->button()
->markAsRead()
])
->sendToDatabase($recipient);
Notification::make()
->title('Product published')
->body('Product published successfully')
->actions([
Action::make('Mark As Read')
->button()
->markAsRead()
])
->sendToDatabase($recipient);
This successfully shows a
Mark As Read
Mark As Read
button on each notification. How can I NOT show the
Mark as Read
Mark as Read
button when the notification is read (e.g. in the notifications table there is a read_at that is not null in such case) I tried it as follows but that does not work:
Notification::make()
->title('Product published')
->body('Product published successfully')
->actions([
Action::make('Mark As Read')
->button()
->markAsRead()
])
->visible(function (Notification $record) {
return $record->read_at !== null;
})
->sendToDatabase($recipient);
Notification::make()
->title('Product published')
->body('Product published successfully')
->actions([
Action::make('Mark As Read')
->button()
->markAsRead()
])
->visible(function (Notification $record) {
return $record->read_at !== null;
})
->sendToDatabase($recipient);
Any idea's?
2 Replies
Dan Harrin
Dan Harrin8mo ago
This is not possible due to how database notifications are serialised to JSON for storager in the database.
Wim
WimOP7mo ago
OK thanks for the feedback. Was hoping to be able to use the read_at field in the database
Want results from more Discord servers?
Add your server