Notifications
Notifications tell users about something that concerns them: a new task, an export that is ready, a deadline that passed. They appear at the bell in the topbar of every panel, with a badge for the unread ones.
use Anvil\Notifications\Notification;
service('notifications')->send($userId, Notification::make('Export ready') ->body('deals.xlsx, 120 rows') ->url('/admin/deals') ->type(Notification::SUCCESS));How it works
Section titled “How it works”- Code sends a notification to one or more users (internal user ids), in the current tenant: Sending.
- It is stored in
anvil_notificationsfor each user. - The bell shows the number of unread notifications, refreshed every minute, and lists the latest 15: Notification center.
- A click marks it as read and opens its link.
- Read notifications are deleted after 90 days: Cleaning up.
Anvil itself notifies about tasks, deadlines, exports and API clients: Sent by Anvil.
What notifications are not
Section titled “What notifications are not”- Not e-mail or push: they are shown in the application only. Send e-mails with CodeIgniter’s email service where users must be reached outside the application.
- Not an audit trail: notifications are personal state and are not written to the audit log; log business events with the audit logger.
- Not toasts: messages after an action (“Saved.”) are toasts that the handler returns, see Record actions.
Run the migrations of Anvil (php spark migrate --all) to create
anvil_notifications, and schedule php spark anvil:prune daily. The bell
is part of every panel; nothing else is needed.