PHPackages                             ez-php/notification - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. ez-php/notification

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

ez-php/notification
===================

Multi-channel notification orchestration for the ez-php framework — mail, broadcast, and database channels with optional queue-backed async delivery

00PHPCI failing

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/ez-php/notification)[ Packagist](https://packagist.org/packages/ez-php/notification)[ RSS](/packages/ez-php-notification/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ez-php/notification
===================

[](#ez-phpnotification)

Multi-channel notification orchestration for ez-php applications. Routes a single notification to any combination of mail, broadcast, and database channels. Optionally dispatches deliveries asynchronously via the queue.

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

[](#installation)

```
composer require ez-php/notification
```

Register the provider in `provider/modules.php`:

```
EzPhp\Notification\NotificationServiceProvider::class,
```

Quick Start
-----------

[](#quick-start)

### 1 — Define a notifiable (e.g. your User model)

[](#1--define-a-notifiable-eg-your-user-model)

```
use EzPhp\Notification\NotifiableInterface;

class User implements NotifiableInterface
{
    public function __construct(
        public readonly int    $id,
        public readonly string $email,
    ) {}

    public function routeNotificationFor(string $channel): string|int
    {
        return match ($channel) {
            'mail'      => $this->email,
            'broadcast' => 'users.' . $this->id,
            'database'  => $this->id,
        };
    }
}
```

### 2 — Define a notification

[](#2--define-a-notification)

```
use EzPhp\Mail\Mailable;
use EzPhp\Notification\Channel\ToMailInterface;
use EzPhp\Notification\NotifiableInterface;
use EzPhp\Notification\NotificationInterface;

class WelcomeNotification implements NotificationInterface, ToMailInterface
{
    public function via(): array
    {
        return ['mail'];
    }

    public function toMail(NotifiableInterface $notifiable): Mailable
    {
        return (new Mailable())
            ->to((string) $notifiable->routeNotificationFor('mail'))
            ->subject('Welcome!')
            ->text('Thanks for signing up.');
    }
}
```

### 3 — Send it

[](#3--send-it)

```
use EzPhp\Notification\Notification;

Notification::send($user, new WelcomeNotification());
```

Channels
--------

[](#channels)

### mail

[](#mail)

Delivers via `ez-php/mail`. The notification must implement `ToMailInterface`:

```
public function toMail(NotifiableInterface $notifiable): Mailable;
```

### broadcast

[](#broadcast)

Delivers via `ez-php/broadcast`. The notification must implement `ToBroadcastInterface`:

```
public function broadcastOn(NotifiableInterface $notifiable): string;   // channel name
public function broadcastAs(NotifiableInterface $notifiable): string;   // event name
public function broadcastWith(NotifiableInterface $notifiable): array;  // payload
```

### database

[](#database)

Persists to the `notifications` table. The notification must implement `ToDatabaseInterface`:

```
public function toDatabase(NotifiableInterface $notifiable): array;  // JSON payload
```

The table is auto-created on first use. To create it via migration instead:

```
-- MySQL
CREATE TABLE notifications (
    id              INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    type            VARCHAR(255) NOT NULL,
    notifiable_type VARCHAR(255) NOT NULL,
    notifiable_id   VARCHAR(255) NOT NULL,
    data            JSON         NOT NULL,
    read_at         DATETIME     NULL,
    created_at      DATETIME     NOT NULL
);

-- SQLite
CREATE TABLE notifications (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    type            TEXT NOT NULL,
    notifiable_type TEXT NOT NULL,
    notifiable_id   TEXT NOT NULL,
    data            TEXT NOT NULL,
    read_at         TEXT NULL,
    created_at      TEXT NOT NULL
);
```

Multi-channel
-------------

[](#multi-channel)

Return multiple channels from `via()` and implement the matching interfaces:

```
class OrderShippedNotification implements
    NotificationInterface,
    ToMailInterface,
    ToBroadcastInterface,
    ToDatabaseInterface
{
    public function via(): array
    {
        return ['mail', 'broadcast', 'database'];
    }

    // toMail(), broadcastOn(), broadcastAs(), broadcastWith(), toDatabase() ...
}
```

Async delivery (queue)
----------------------

[](#async-delivery-queue)

Add `ShouldQueueInterface` to defer mail and broadcast channels via the queue:

```
use EzPhp\Notification\ShouldQueueInterface;

class WelcomeNotification implements NotificationInterface, ShouldQueueInterface, ToMailInterface
{
    // ...
}
```

When `QueueInterface` is bound (i.e. `QueueServiceProvider` is registered), the Notifier pushes `SendMailNotificationJob` / `SendBroadcastNotificationJob` onto the queue instead of delivering synchronously. The `database` channel always runs synchronously.

To force synchronous delivery regardless of `ShouldQueueInterface`:

```
Notification::sendNow($user, new WelcomeNotification());
```

Service Provider wiring
-----------------------

[](#service-provider-wiring)

`NotificationServiceProvider` registers the following channels automatically:

ChannelRequiresOptional`mail``MailServiceProvider`—`broadcast``BroadcastServiceProvider`—`database``DatabaseServiceProvider`yes — omitted if not boundQueue support (`ShouldQueueInterface`) is also optional — if `QueueServiceProvider` is not registered, all notifications are sent synchronously.

Testing
-------

[](#testing)

Inject a real `Notifier` with spy channels in your tests:

```
use EzPhp\Notification\Notification;
use EzPhp\Notification\Notifier;

protected function setUp(): void
{
    $this->spyChannel = new SpyChannel();
    Notification::setNotifier(new Notifier(['mail' => $this->spyChannel]));
}

protected function tearDown(): void
{
    Notification::resetNotifier();
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

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

---

Top Contributors

[![AU9500](https://avatars.githubusercontent.com/u/122030400?v=4)](https://github.com/AU9500 "AU9500 (2 commits)")

### Embed Badge

![Health badge](/badges/ez-php-notification/health.svg)

```
[![Health](https://phpackages.com/badges/ez-php-notification/health.svg)](https://phpackages.com/packages/ez-php-notification)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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