audentio / laravel-notifications
Base notifications and notification preferences system for Audentio platforms.
Requires
- php: >=8.1
- ext-json: *
- audentio/laravel-base: ^1.1|^2.0
Requires (Dev)
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- dev-master
- 0.3.20
- 0.3.19
- 0.3.18
- 0.3.17
- 0.3.16
- 0.3.15
- 0.3.14
- 0.3.13
- 0.3.12
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.3.0-alpha.3
- 0.3.0-alpha.2
- 0.3.0-alpha.1
- 0.2.x-dev
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.2.0-alpha.4
- 0.2.0-alpha.3
- 0.2.0-alpha.2
- 0.2.0-alpha.1
- 0.1.x-dev
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- 0.0.1-beta.4
- 0.0.1-beta.3
- 0.0.1-beta.2
- 0.0.1-beta.1
- dev-graphql-update
This package is auto-updated.
Last update: 2026-05-05 19:25:28 UTC
README
Notifications and notification preference system for Audentio Laravel platforms. Provides a database-backed notification preference system with per-channel defaults, per-tenant overrides, per-user overrides, a GraphQL API, and optional push notification support.
Requirements
- PHP 8.1+
- Laravel 12
audentio/laravel-base
Installation
composer require audentio/laravel-notifications
Publish and run the migrations:
php artisan vendor:publish --tag=audentio-notifications-config php artisan migrate
Publish the model stubs:
php artisan vendor:publish --tag=audentio-notifications-models
Setup
1. Implement models
The published stubs in app/Models/ need to be wired up to your application. At minimum:
NotificationPreference — extend getDefaultUserNotificationPreferenceValue() if needed. The getName() method must return a human-readable label (typically from a translation key).
NotificationPreferenceGroup — same, getName() must be implemented.
UserNotificationPreference — no changes needed beyond the stub.
2. Add the trait to your User model
use Audentio\LaravelNotifications\Models\Interfaces\NotifiableUserInterface; use Audentio\LaravelNotifications\Models\Traits\NotifiableUserTrait; class User extends Model implements NotifiableUserInterface { use NotifiableUserTrait; public function isEmailVerified(): bool { return $this->email_verified_at !== null; } }
3. Create notification handlers
Extend AbstractNotification and implement getNotificationPreferenceId():
use Audentio\LaravelNotifications\Notifications\AbstractNotification; class NewMessageNotification extends AbstractNotification { public function getNotificationPreferenceId(): string { return 'newMessage'; } public function toMail($notifiable): MailMessage { return (new MailMessage)->subject('New message'); } }
4. Seed preferences
Run your NotificationPreferencesAndGroupsTableSeeder after adding handlers. The seeder auto-discovers handlers and creates NotificationPreference records.
Notification Preference Hierarchy
User preferences follow a 3-level fallback (highest priority first):
| Level | Source | Stored in |
|---|---|---|
| 3 | User override | user_notification_preferences.disabled_channels |
| 2 | Tenant override | App-provided via getNotificationPreferenceTenantDefaults() |
| 1 | Global default | notification_preferences.default_disabled_channels |
When no record exists at a level, the next level is used. An empty disabled_channels array means all channels are enabled.
Setting global defaults
Set default_disabled_channels when seeding a preference:
'streamGoLive' => [ 'available_channels' => ['notification', 'mail'], 'default_disabled_channels' => ['mail'], // mail off by default for all users ],
Tenant-level overrides
Override getNotificationPreferenceTenantDefaults() on your User model to load tenant-specific defaults. This is called once per getUserNotificationPreferenceValues() call — load all tenant preferences in a single query:
public function getNotificationPreferenceTenantDefaults(): Collection { $tenant = $this->getCurrentTenant(); if (!$tenant) { return collect(); } return TenantNotificationPreference::where('tenant_id', $tenant->id)->get(); }
Optional: Disable automatic migrations
If you manage migrations manually:
// In a service provider LaravelNotifications::skipMigrations();
Optional: Push notifications
Enable push support in config/audentioNotifications.php:
'push_enabled' => true, 'push_handler_classes' => [ 'expo' => \Audentio\LaravelNotifications\PushHandlers\ExpoPushHandler::class, 'fcm' => \Audentio\LaravelNotifications\PushHandlers\FirebasePushHandler::class, ],
Run the additional push migrations:
php artisan migrate
Push subscriptions are managed via the routeNotificationForPush() method on your User model (provided by NotifiableUserTrait — override if needed).
GraphQL
The package auto-registers a GraphQL schema when audentio/laravel-graphql is present. Exposed types, queries, and mutations include:
- Queries:
notifications,notificationPreferenceGroups - Mutations:
updateViewerNotificationPreferenceValue,dismissNotification,markReadNotification,markUnreadNotification,markReadAllNotifications,dismissAllNotifications - Types:
NotificationPreference,NotificationPreferenceGroup,UserNotificationPreferenceValue,NotificationChannelEnum
Override individual types via graphQL_schema_overrides in the config.
To disable GraphQL registration:
LaravelNotifications::skipGraphQLSchema();
Testing
composer test
License
MIT