Getting Started

Installation

Install the latest v1.x release or the development version of NotificationCompass.

NotificationCompass supports Laravel 11 and 12 with PHP 8.2 or later.

Install the latest v1.x release

Install the latest stable version with Composer:

Terminal
composer require evanschleret/notificationcompass

Install the development version

Use the main branch to test unreleased changes. This branch may contain breaking changes and should not be used in production:

Terminal
composer config repositories.notificationcompass vcs https://github.com/EvanSchleret/NotificationCompass
composer require evanschleret/notificationcompass:dev-main

Laravel discovers the service provider automatically. The provider registers the definition registry, preference resolver, context authorizers, user preference store, context preference store, context policy manager, and NotificationSending listener. Bind NotificationContextAuthorizer and NotificationContextPolicyAuthorizer in an application service provider when contextual access or policy administration depends on application-specific authorization rules.

Publish configuration

Publish the configuration when you need to change the table name or define notifications in application configuration:

Terminal
php artisan vendor:publish --tag=notificationcompass-config

Run the package migration:

Terminal
php artisan migrate
The default tables are notificationcompass_preferences and notificationcompass_context_preferences. Change notificationcompass.table or notificationcompass.context_table before migrating if your application uses different names.

Add the model trait

Add HasNotificationPreferences to the model that receives notifications:

app/Models/User.php
use NotificationCompass\Concerns\HasNotificationPreferences;

class User extends Authenticatable
{
    use HasNotificationPreferences;
}

Continue with definitions before exposing preference controls in your UI.