Filament notifications with action buttons
Send a Filament 4 database notification with View and Acknowledge buttons, mark-as-read behaviour and a one-time signed link.
FilamentNotificationsfilamentnotificationsactionssigned-url
Code
Needs: filament/filament@^4.0
How it works
What it solves
A plain notification tells people something happened but leaves the next step to them. Buttons inside the notification, "View" and "Acknowledge", turn an alert into a two-click workflow straight from the bell menu.
How it works
IncidentNotifier::opened() builds a Filament Notification with a title, body, warning icon and persistent() so it stays until dismissed. For each recipient it attaches Action objects and calls sendToDatabase().
The View button is a normal link to the incident resource page, opened in a new tab, and markAsRead() clears the unread state when it is clicked. The Acknowledge button points at a temporary signed route valid for six hours. The user id is part of the signed URL, and the controller refuses anybody else.
The controller keeps the operation idempotent with syncWithoutDetaching, so double clicks and repeated visits cause no duplicate rows. It then shows a success toast and returns to the panel.
Adapting it
Swap the model, title and route names. For quick in-page responses without a redirect, use Action::dispatch('event-name') and a Livewire listener on pages that are always loaded; the signed URL works everywhere, including emails. Add ->sendToDatabase($user, isEventDispatched: true) if the bell should update instantly with broadcasting.
Pitfalls
- Database notifications require
php artisan make:notifications-tableand->databaseNotifications()on the panel. - A GET request that changes state is only acceptable because it is signed, idempotent and user-bound.
- Rebuilding actions inside the loop mutates the same object; send in the same iteration, as shown.
How to use it
- Run
php artisan make:notifications-table && php artisan migrate, and add->databaseNotifications()to the panel. - Add the notifier and controller, then register the signed
incidents.acknowledgeroute. - Create an
acknowledgedBymany-to-many relation onIncidentwith anacknowledged_atpivot column. - Call
IncidentNotifier::opened($incident, $onCallUsers)when an incident starts. - Open the bell menu in the panel to see both buttons.
Licence: DEV3 Snippet Licence. Free to use, change and ship in personal and commercial projects. Attribution is appreciated, not required. Please do not redistribute snippets as a collection.