Reference

Configuration

Configure the preference table, defaults, channels, definitions, and providers.

The published config/notificationcompass.php file contains these options:

config/notificationcompass.php
return [
    'table' => 'notificationcompass_preferences',
    'context_table' => 'notificationcompass_context_preferences',
    'definitions' => [],
    'definition_providers' => [],
    'default' => false,
    'channels' => [],
    'unknown_notifications' => 'allow',
    'authorization' => [
        'strict' => false,
    ],
    'cache' => [
        'enabled' => true,
        'store' => null,
        'ttl' => 300,
        'prefix' => 'notificationcompass:preferences',
    ],
];

default is the final fallback. channels maps channel names to defaults, for example ['mail' => true, 'database' => false].

unknown_notifications controls notifications that have no matching definition in the registry:

  • allow keeps Laravel's normal behavior and is the default.
  • deny blocks delivery and returns the unknown_notification decision reason.
  • throw raises a LogicException so missing definitions fail immediately.

Use deny or throw in production and test environments when every notification must be registered explicitly.

Set authorization.strict to true when the application must explicitly bind both NotificationContextAuthorizer and NotificationContextPolicyAuthorizer. The default authorizers then deny contextual access and policy operations until the application provides its own implementations.

context_table configures the table used by the default EloquentNotificationContextPreferenceStore for context-level policies.

The resolved preference cache is enabled by default and stores decisions for cache.ttl seconds. Set cache.enabled to false to disable it. When cache.store is null, NotificationCompass uses the store selected by Laravel's cache.default configuration. Set it to a store name when the package should use a specific Laravel cache store. cache.prefix namespaces its keys.

Define notifications in configuration

'definitions' => [
    'security.alert' => [
        'channels' => ['mail', 'database'],
        'defaults' => ['mail' => true],
        'mandatory_channels' => ['mail'],
        'metadata' => [
            'label' => 'Security alerts',
            'description' => 'Important security notifications for the account.',
            'category' => 'security',
            'order' => 10,
        ],
        'channel_metadata' => [
            'mail' => [
                'label' => 'Email',
                'description' => 'Send security alerts by email.',
                'visible' => true,
            ],
            'database' => ['visible' => false],
        ],
    ],
    'digest.weekly' => [
        'channels' => ['mail'],
        'opt_in' => true,
    ],
],

The metadata object exposes the descriptive label, long description, category, and numeric display order. The channel_metadata object exposes descriptive channel labels and descriptions, plus the visible flag used by settings interfaces. These objects do not contain translations, icons, or rendering conventions; the application remains responsible for those concerns.

The definition also supports context_defaults, notification_class, channel_options, supported_contexts, requires_context, and configurable. Set requires_context to true when the notification must be associated with a context. If no context is supplied by the notification or the gate call, the package blocks delivery instead of using global preferences.

Register definitions in code

Implement NotificationDefinitionProvider and add its class to definition_providers when definitions should be assembled by application code.