The notifications module stores notifications in the database and sends them to iOS and Android devices through Firebase Cloud Messaging. The same notifications feed the notification center of the app.

Installation

  1. Save the service account of your Firebase project to credentials/firebase_credentials.json.
  2. Enable the module and run php artisan admin:migrate.
  3. Schedule the sending command. Run a queue worker as well when you use instant notifications.
config/admin_helpers.php
routes/console.php
The cleanup of old notifications and dead device tokens is scheduled automatically.

Notification model

Extend the package model and add the columns of relations:
app/Models/Notification/AppNotification.php

Notification types

Define the types in the notificationsList() function of your project:
app/Utilities/helpers.php
Also define getNotificationsTypes(), the list of types users can turn off in the app, and getPlatform(), the platform of the current request:
app/Utilities/helpers.php

User model

app/Models/User.php
Save the device token of the app after login:
The token is linked to the current Sanctum token, so logout removes it. The login response lists the tokens of the user in device_tokens. Add the Notification tokens tab to the user form with notificationsTokensTab():
app/Models/User.php

Creating notifications

Unknown types create nothing.

Notification center

app/Http/Controllers/NotificationController.php
onlyMine() returns notifications of the signed in user and the global ones. Each row contains id, type, data, read_at, title, message and created_at. Override the onlyMine and isNotPersistent scopes in your model to limit them further, e.g. by the app.

Testing

In the local and stagging environments, notifications are sent only to device tokens marked for debugging. Mark a token with the Allow notifications in DEV mode button in the notification tokens tab. New tokens are marked automatically in these environments. Sending is logged into storage/logs/notification.log.