PHPackages                             cerbero/notifiable-exception - 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. cerbero/notifiable-exception

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

cerbero/notifiable-exception
============================

Laravel package to send notifications when some exceptions are thrown.

1.1.1(6y ago)761711MITPHPPHP ^7.0CI failing

Since Oct 8Pushed 1y ago4 watchersCompare

[ Source](https://github.com/cerbero90/notifiable-exception)[ Packagist](https://packagist.org/packages/cerbero/notifiable-exception)[ Docs](https://github.com/cerbero90/notifiable-exception)[ Fund](https://paypal.me/AndreaMarcoSartori)[ RSS](/packages/cerbero-notifiable-exception/feed)WikiDiscussions develop Synced today

READMEChangelogDependencies (8)Versions (5)Used By (0)

Notifiable Exception
====================

[](#notifiable-exception)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d474ec5d84c5e3d9dc9003a3fb46961d005bdda49a22a973a3d83ccee65ad78b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365726265726f2f6e6f7469666961626c652d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/notifiable-exception)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/71c6cbb434463a87a81df1e1819ade824d04644523cb7dec235293cc56214d86/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6365726265726f39302f6e6f7469666961626c652d657863657074696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cerbero90/notifiable-exception)[![Coverage Status](https://camo.githubusercontent.com/cb4da03cb7e55dcac1560b51aa00746dee382f944c0ef549410811980aaaf004/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6365726265726f39302f6e6f7469666961626c652d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cerbero90/notifiable-exception/code-structure)[![Quality Score](https://camo.githubusercontent.com/2ad684f180bb265c5d0ca98aa0c97c185b99e84109cc819be925e06d4d873993/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6365726265726f39302f6e6f7469666961626c652d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cerbero90/notifiable-exception)[![Total Downloads](https://camo.githubusercontent.com/c71a8c65e11da53e8cdebf86fb0bbd0ba8c456995396317326e578896084f733/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6365726265726f2f6e6f7469666961626c652d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/notifiable-exception)

Laravel package to send [notifications](https://laravel.com/docs/notifications) when exceptions are thrown.

Install
-------

[](#install)

Via Composer

```
$ composer require cerbero/notifiable-exception
```

We might need to install other packages depending on the notification channels we want to use (e.g. Slack, Telegram). Please refer to [Laravel Notification Channels](http://laravel-notification-channels.com) for more information.

For better performance notifications are queued, please check the [documentation](https://laravel.com/docs/queues) to find out what are the requirements for your queue driver.

Usage
-----

[](#usage)

In order to be notifiable, exceptions need to implement the `Notifiable` interface and use the `Notifies` trait:

```
use Cerbero\NotifiableException\Notifiable;
use Cerbero\NotifiableException\Notifies;
use Exception;

class UrgentException extends Exception implements Notifiable
{
    use Notifies;
}
```

Otherwise, if we don't need to extend a particular exception class, we may just extend the `NotifiableException` for convenience:

```
use Cerbero\NotifiableException\Exceptions\NotifiableException;

class UrgentException extends NotifiableException
```

When notifiable exceptions are not handled manually in a `try-catch`, they are notified automatically. However when we actually need to handle them we can send their notifications by calling the `notify()` method in the `try-catch`:

```
try {
    $this->methodThrowingNotifiableException();
} catch (NotifiableException $e) {
    $e->notify();
    // exception handling logic
}
```

Sometimes we might want some channel routes to always be notified when an exception is thrown. If so, we can set default routes for every channel we want to notify in `config/notifiable_exception.php`:

```
$ php artisan vendor:publish --tag=notifiable_exception_config
```

As an example, the following configuration defines a Slack and a mail route that will always be notified when any notifiable exception is thrown:

```
'default_routes' => [
    'mail' => [
        'example@test.com',
    ],
    'slack' => [
        'https://hooks.slack.com/services/xxx/xxx/xxx',
    ],
],
```

> **Please note**: this README shows routes in the code for convenience, however it is recommended to set routes in environment variables that can then be read from configuration files.

Different routes might need to be notified depending on what instance of notifiable exception is thrown. Ad hoc channels and routes can be defined in notifiable exceptions themselves by overriding the method `getCustomRoutes()`:

```
class UrgentException extends NotifiableException
{
    protected function getCustomRoutes(): array
    {
        return [
            'nexmo' => [
                '15556666666',
            ],
        ];
    }
}
```

In the example above, the phone number `+1 555-666-6666` will receive an SMS whenever `UrgentException` is thrown, alongside with the default routes specified in the configuration.

If we want an exception to notify only its custom routes while ignoring the default ones, we can instruct the method `overridesRoutes()` to do so:

```
protected function overridesRoutes(): bool
{
    return true;
}
```

Messages to send can be customized per channel by overriding the method `getMessages()`:

```
public function getMessages(): array
{
    return [
        'mail' => (new MailMessage)
            ->error()
            ->subject('An error occurred')
            ->line($this->getMessage()),
        'slack' => (new SlackMessage)
            ->error()
            ->content($content)
            ->attachment(function (SlackAttachment $attachment) {
                $attachment
                    ->title($this->getMessage())
                    ->fields([
                        'File' => $this->getFile(),
                        'Line' => $this->getLine(),
                        'Code' => $this->getCode(),
                        'Previous exception' => $this->getPrevious() ? get_class($this->getPrevious()) : 'none',
                    ]);
            }),
        'nexmo' => (new NexmoMessage)->content($this->getMessage()),
    ];
}
```

By default Laravel supports some notification channels (e.g. `mail`, `slack`), however custom channel classes need to be specified when using [third-party solutions](http://laravel-notification-channels.com). We can define them by overriding the method `getCustomChannels()`:

```
use NotificationChannels\Telegram\TelegramChannel;

...

public function getCustomChannels(): array
{
    return [
        'telegram' => TelegramChannel::class,
    ];
}
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrea Marco Sartori](https://github.com/cerbero90)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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

Every ~74 days

Total

3

Last Release

2258d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/596523?v=4)[Matteo Picciolini](/maintainers/cerbero)[@cerbero](https://github.com/cerbero)

---

Top Contributors

[![cerbero90](https://avatars.githubusercontent.com/u/5838106?v=4)](https://github.com/cerbero90 "cerbero90 (39 commits)")

---

Tags

laravelnotificationsexceptions

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cerbero-notifiable-exception/health.svg)

```
[![Health](https://phpackages.com/badges/cerbero-notifiable-exception/health.svg)](https://phpackages.com/packages/cerbero-notifiable-exception)
```

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[usamamuneerchaudhary/filament-notifier

A powerful notification system for FilamentPHP that handles multi-channel notifications with template management, scheduling, and real-time delivery. Built for developers who need enterprise-grade notifications without the complexity.

321.1k](/packages/usamamuneerchaudhary-filament-notifier)

PHPackages © 2026

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