Skip to content

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));
  1. Code sends a notification to one or more users (internal user ids), in the current tenant: Sending.
  2. It is stored in anvil_notifications for each user.
  3. The bell shows the number of unread notifications, refreshed every minute, and lists the latest 15: Notification center.
  4. A click marks it as read and opens its link.
  5. Read notifications are deleted after 90 days: Cleaning up.

Anvil itself notifies about tasks, deadlines, exports and API clients: Sent by Anvil.

  • 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.