PHPackages                             makbeth/yii2-notifications - 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. makbeth/yii2-notifications

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

makbeth/yii2-notifications
==========================

The extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack etc. Notifications may also be stored in a database so they may be displayed in your web interface. In this version issue with the table name has been fixed

v1.2.0(9y ago)039MITPHPPHP &gt;=5.4.0

Since Sep 8Pushed 6y agoCompare

[ Source](https://github.com/makbeth/yii2-notifications)[ Packagist](https://packagist.org/packages/makbeth/yii2-notifications)[ Docs](https://github.com/tuyakhov/yii2-notifications)[ RSS](/packages/makbeth-yii2-notifications/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (16)Used By (0)

🔔 Notifications for Yii2
========================

[](#bell-notifications-for-yii2)

This Yii2 extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack, Telegram etc. Notifications may also be stored in a database so they may be displayed in your web interface.

Typically, notifications should be short, informational messages that notify users of something that occurred in your application. For example, if you are writing a billing application, you might send an "Invoice Paid" notification to your users via the email and SMS channels.

[![Latest Stable Version](https://camo.githubusercontent.com/91972fb57a1c8731aa3ec69100306835814d97298b30db790e4953e418434451/68747470733a2f2f706f7365722e707567782e6f72672f747579616b686f762f796969322d6e6f74696669636174696f6e732f762f737461626c65)](https://packagist.org/packages/tuyakhov/yii2-notifications) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/21f8db647699ed05a348bf27e82b8811348479f10bc8142bf39c75360b80296d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747579616b686f762f796969322d6e6f74696669636174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tuyakhov/yii2-notifications/?branch=master) [![Build Status](https://camo.githubusercontent.com/db14502d1e5bfd424b57db9db906bc81eeb9092dc2ccb17f0d57e52910f3c41b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747579616b686f762f796969322d6e6f74696669636174696f6e732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tuyakhov/yii2-notifications/build-status/master) [![Code Climate](https://camo.githubusercontent.com/157f66ba26fd821d900f7067873975aa98c5f3b8b0e1b52b5144e4902fa9410d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f747579616b686f762f796969322d6e6f74696669636174696f6e732f6261646765732f6770612e737667)](https://codeclimate.com/github/tuyakhov/yii2-notifications)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist tuyakhov/yii2-notifications "*"

```

or add

```
"tuyakhov/yii2-notifications": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

The following example shows how to create a Notifier instance and send your first notification:

```
$notifier = new \tuyakhov\notifications\Notifier([
  'channels' => [...],
]);
$notifier->send($recipients, $notifications);
```

Notifier is often used as an application component and configured in the application configuration like the following:

```
[
   'components' => [
       'notifier' => [
           'class' => '\tuyakhov\notifications\Notifier',
           'channels' => [
               'mail' => [
                   'class' => '\tuyakhov\notifications\channels\MailChannel',
                   'from' => 'no-reply@example.com'
               ],
               'sms' => [
                   'class' => '\tuyakhov\notifications\channels\TwilioChannel',
                   'accountSid' => '...',
                   'authToken' => '...',
                   'from' => '+1234567890'
               ],
               'telegram' => [
                    'class' => '\tuyakhov\notifications\channels\TelegramChannel',
                    'botToken' => '...'
                ],
               'database' => [
                    'class' => '\tuyakhov\notifications\channels\ActiveRecordChannel'
               ]
           ],
       ],
   ],
]
```

Once the component is configured it may be used for sending notifications:

```
$recipient = User::findOne(1);
$notification = new InvoicePaid($invoice);

Yii::$app->notifier->send($recipient, $notification);
```

Each notification class should implement `NotificationInterface` and contain a `viaChannels` method and a variable number of message building methods (such as `exportForMail`) that convert the notification to a message optimized for that particular channel. Example of a notification that covers the case when an invoice has been paid:

```
use tuyakhov\notifications\NotificationInterface;
use tuyakhov\notifications\NotificationTrait;

class InvoicePaid implements NotificationInterface
 {
    use NotificationTrait;

    private $invoice;

    public function __construct($invoice)
    {
        $this->invoice = $invoice;
    }

    /**
     * Prepares notification for 'mail' channel
     */
    public function exportForMail() {
        return Yii::createObject([
           'class' => '\tuyakhov\notifications\messages\MailMessage',
           'view' => ['html' => 'invoice-paid'],
           'viewData' => [
               'invoiceNumber' => $this->invoice->id,
               'amount' => $this->invoice->amount
           ]
        ])
    }

    /**
     * Prepares notification for 'sms' channel
     */
    public function exportForSms()
    {
        return \Yii::createObject([
            'class' => '\tuyakhov\notifications\messages\SmsMessage',
            'text' => "Your invoice #{$this->invoice->id} has been paid"
        ]);
    }

    /**
     * Prepares notification for 'database' channel
     */
    public function exportForDatabase()
    {
        return \Yii::createObject([
            'class' => '\tuyakhov\notifications\messages\DatabaseChannel',
            'subject' => "Invoice has been paid",
            'body' => "Your invoice #{$this->invoice->id} has been paid",
            'data' => [
                'actionUrl' => ['href' => '/invoice/123/view', 'label' => 'View Details']
            ]
        ]);
    }
 }
```

You may use the NotifiableInterface and NotifiableTrait on any of your models:

```
use yii\db\ActiveRecord;
use tuyakhov\notifications\NotifiableTrait;
use tuyakhov\notifications\NotifiableInterface;

class User extends ActiveRecord implements NotifiableInterface
{
   use NotifiableTrait;

   public function routeNotificationForMail()
   {
        return $this->email;
   }
}
```

#### Database notifications

[](#database-notifications)

The `database` notification channel stores the notification information in a database table.
You can query the table to display the notifications in your application's user interface. But, before you can do that, you will need to create a database table to hold your notifications. To do this, you can use the migration that comes with this extension:

```
yii migrate --migrationPath=@vendor/tuyakhov/yii2-notifications/src/migrations

```

or

```
'controllerMap' => [
    ...
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationNamespaces' => [
            'tuyakhov\notifications\migrations',
        ],
    ],
    ...
],
```

```
php yii migrate/up

```

**Accessing The Notifications**
Once notifications are stored in the database, you need a convenient way to access them from your notifiable entities. The `NotifiableTrait`, which comes with this extension, includes a notifications relationship that returns the notifications for the entity. To fetch notifications, you may access this method like any other `ActiveRecord` relationship.

```
$model = User::findOne(1);
foreach($model->notifications as $notification) {
    echo $notification->subject;
}
```

If you want to retrieve only the "unread" notifications, you may use the `unreadNotifications` relationship.

```
$model = User::findOne(1);
foreach($model->unreadNotifications as $notification) {
    echo $notification->subject;
}
```

You can access custom JSON data that describes the notification and was added using `DatabaseMessage`:

```
/** @var $notificatiion tuyakhov\notifications\models\Notificatios */
$actionUrl = $notification->data('actionUrl'); // ['href' => '/invoice/123/pay', 'label' => 'Pay Invoice']
```

**Marking Notifications As Read**
Typically, you will want to mark a notification as "read" when a user views it. The `ReadableBehavior` in `Notification` model provides a `markAsRead` method, which updates the read\_at column on the notification's database record:

```
$model = User::findOne(1);
foreach($model->unreadNotifications as $notification) {
    $notification->markAsRead();

    // the following methods are also available
    $notification->markAsUnread();
    $notification->isUnread();
    $notification->isRead();
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 82.9% 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

Every ~0 days

Total

14

Last Release

3532d ago

Major Versions

v0.0.6 → v1.0.02016-09-08

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7573343?v=4)[Alexandr Baranov](/maintainers/makbeth)[@makbeth](https://github.com/makbeth)

---

Top Contributors

[![tuyakhov](https://avatars.githubusercontent.com/u/7713205?v=4)](https://github.com/tuyakhov "tuyakhov (29 commits)")[![Julielesss](https://avatars.githubusercontent.com/u/36435376?v=4)](https://github.com/Julielesss "Julielesss (4 commits)")[![gitrequests](https://avatars.githubusercontent.com/u/12627650?v=4)](https://github.com/gitrequests "gitrequests (1 commits)")[![mrbig00](https://avatars.githubusercontent.com/u/1911197?v=4)](https://github.com/mrbig00 "mrbig00 (1 commits)")

---

Tags

emailnotificationsslacksmsyii2yiitamarintransactional messages

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/makbeth-yii2-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/makbeth-yii2-notifications/health.svg)](https://phpackages.com/packages/makbeth-yii2-notifications)
```

###  Alternatives

[tuyakhov/yii2-notifications

The extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack etc. Notifications may also be stored in a database so they may be displayed in your web interface.

6735.5k2](/packages/tuyakhov-yii2-notifications)[nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

87129.2k2](/packages/nterms-yii2-mailqueue)[djagya/yii2-sparkpost

A library provides Yii2 integration with SparkPost mail service

1816.3k](/packages/djagya-yii2-sparkpost)[baibaratsky/php-mailgun

Mailgun API PHP library and Yii extension (as well as Yii2)

3224.6k](/packages/baibaratsky-php-mailgun)[craftpulse/craft-notifications

Send notifications across a variety of delivery channels, including mail and Slack. Notifications may also be stored in a database so they may be displayed in your web interface.

551.2k](/packages/craftpulse-craft-notifications)

PHPackages © 2026

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