PHPackages                             scabarcas/laravel-notify-matrix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. scabarcas/laravel-notify-matrix

ActiveLibrary[Database &amp; ORM](/categories/database)

scabarcas/laravel-notify-matrix
===============================

Manage per-user notification preferences in Laravel, with channel-level opt-in and opt-out.

v0.1.0(1mo ago)72MITPHPPHP ^8.3CI passing

Since May 28Pushed 1mo agoCompare

[ Source](https://github.com/scabarcas17/laravel-notify-matrix)[ Packagist](https://packagist.org/packages/scabarcas/laravel-notify-matrix)[ RSS](/packages/scabarcas-laravel-notify-matrix/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (10)Versions (2)Used By (0)

Laravel Notify Matrix
=====================

[](#laravel-notify-matrix)

[![CI](https://github.com/scabarcas17/laravel-notify-matrix/actions/workflows/ci.yml/badge.svg)](https://github.com/scabarcas17/laravel-notify-matrix/actions/workflows/ci.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/d46ace48887e3f72c342088c299e6ecf847d3c6e8060cf27d5b04d9126f1a240/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363616261726361732f6c61726176656c2d6e6f746966792d6d61747269782e737667)](https://packagist.org/packages/scabarcas/laravel-notify-matrix)[![Total Downloads](https://camo.githubusercontent.com/3ec33c89ab285ee7ae1cd8921630fb45c5e52492aba568998668630616acabb3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7363616261726361732f6c61726176656c2d6e6f746966792d6d61747269782e737667)](https://packagist.org/packages/scabarcas/laravel-notify-matrix)[![PHP Version](https://camo.githubusercontent.com/e210fd4c4e7c313299ea939527ee67145b148ecf9486d5f3b4f1211e2d01d29d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7363616261726361732f6c61726176656c2d6e6f746966792d6d61747269782e737667)](https://packagist.org/packages/scabarcas/laravel-notify-matrix)[![License](https://camo.githubusercontent.com/f94fd2a91dc7e22891bde58f9624bdb3228abe62064334813527a1647a1d3911/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363616261726361732f6c61726176656c2d6e6f746966792d6d61747269782e737667)](https://github.com/scabarcas17/laravel-notify-matrix/blob/main/LICENSE)

Manage per-user notification preferences in Laravel. Each user can opt in or out of channels for each notification group.

Installation
------------

[](#installation)

```
composer require scabarcas/laravel-notify-matrix
```

```
php artisan vendor:publish --tag=notify-matrix-config
php artisan vendor:publish --tag=notify-matrix-migrations
php artisan migrate
```

Quick start
-----------

[](#quick-start)

Add the trait to the user model (or any notifiable):

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use Scabarcas\LaravelNotifyMatrix\Concerns\HasNotificationPreferences;

class User extends Authenticatable
{
    use HasNotificationPreferences;
}
```

Tag each notification with the group it belongs to:

```
use Illuminate\Notifications\Notification;
use Scabarcas\LaravelNotifyMatrix\Attributes\NotificationGroup;

#[NotificationGroup('orders')]
class OrderShipped extends Notification
{
    public function via($notifiable): array
    {
        return ['mail', 'database'];
    }
}
```

Read and write preferences from the model:

```
$user->wants('orders', 'mail');                // true | false
$user->wants(OrderShipped::class, 'mail');     // resolves the group via the attribute
$user->setPreference('orders', 'mail', false);
$user->enable('orders', 'mail');
$user->disable('orders', 'mail');
$user->getPreferences();
$user->getPreferencesForGroup('orders');
$user->clearPreferences('orders');
```

With the trait on the notifiable and the attribute on the notification, the dispatch listener filters channels according to stored preferences. Forced channels are always delivered.

Configuration
-------------

[](#configuration)

```
return [
    'table' => 'notification_preferences',

    // Applied when no preference exists for a channel within a group.
    // Each group may override this below. Supported: "opt_in", "opt_out".
    'default_policy' => 'opt_in',

    'groups' => [
        'marketing' => [
            'default_policy' => 'opt_out',
        ],

        'security' => [
            'default_policy' => 'opt_in',
            'forced'         => ['mail'],
        ],
    ],

    'class_map' => [
        // Map notifications that cannot be annotated directly.
        // \Vendor\Pkg\Notifications\InvoicePaid::class => 'billing',
    ],

    'cache' => [
        'enabled' => true,
        'ttl'     => 300,
        'store'   => null,
    ],
];
```

### Forced channels

[](#forced-channels)

Channels listed under `groups..forced` are delivered even when the user has opted out. Common use cases are security alerts and account verification messages.

### Class map

[](#class-map)

Third-party notification classes that cannot be annotated with `#[NotificationGroup]` can be mapped to a group through the `class_map` entry. Annotated classes always take precedence over the map.

How it works
------------

[](#how-it-works)

The package registers a listener for `Illuminate\Notifications\Events\NotificationSending` that runs before each channel dispatch:

1. If the notifiable does not use `HasNotificationPreferences`, the listener does not interfere.
2. If the notification has neither a `#[NotificationGroup]` attribute nor a `class_map` entry, the listener does not interfere.
3. If the channel is listed as forced for the group, the channel is delivered.
4. If the user has a stored preference for the channel, that value decides.
5. Otherwise, the group default policy decides (or the global default if the group has none).

Testing
-------

[](#testing)

```
composer install
composer test
composer analyse
composer format
```

Author
------

[](#author)

**Sebastian Cabarcas Berrio** ·  · [@scabarcas17](https://github.com/scabarcas17)

License
-------

[](#license)

MIT © Sebastian Cabarcas Berrio

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance89

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

57d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d6b48c27263c160584bae46388bf661b9f7fe19d56a90eb91c0bba5276996d14?d=identicon)[scabarcas17](/maintainers/scabarcas17)

---

Top Contributors

[![scabarcas17](https://avatars.githubusercontent.com/u/42840369?v=4)](https://github.com/scabarcas17 "scabarcas17 (11 commits)")

---

Tags

eloquentlaravellaravel-packagenotification-preferencesnotificationsopt-inphpphp-attributeslaravelnotificationssaaschannelsopt inuser-preferencesopt-outnotification-preferencesnotification-routing

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/scabarcas-laravel-notify-matrix/health.svg)

```
[![Health](https://phpackages.com/badges/scabarcas-laravel-notify-matrix/health.svg)](https://phpackages.com/packages/scabarcas-laravel-notify-matrix)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k30.2M151](/packages/laravel-cashier)[spatie/laravel-health

Monitor the health of a Laravel application

87912.0M177](/packages/spatie-laravel-health)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k21](/packages/fleetbase-core-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
