Download the PHP package cerbero/notifiable-exception without Composer
On this page you can find all versions of the php package cerbero/notifiable-exception. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cerbero/notifiable-exception
More information about cerbero/notifiable-exception
Files in cerbero/notifiable-exception
Package notifiable-exception
Short Description Laravel package to send notifications when some exceptions are thrown.
License MIT
Homepage https://github.com/cerbero90/notifiable-exception
Informations about the package notifiable-exception
Notifiable Exception
Laravel package to send notifications when exceptions are thrown.
Install
Via Composer
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 for more information.
For better performance notifications are queued, please check the documentation to find out what are the requirements for your queue driver.
Usage
In order to be notifiable, exceptions need to implement the Notifiable
interface and use the Notifies
trait:
Otherwise, if we don't need to extend a particular exception class, we may just extend the NotifiableException
for convenience:
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
:
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
:
As an example, the following configuration defines a Slack and a mail route that will always be notified when any notifiable exception is thrown:
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()
:
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:
Messages to send can be customized per channel by overriding the method getMessages()
:
By default Laravel supports some notification channels (e.g. mail
, slack
), however custom channel classes need to be specified when using third-party solutions. We can define them by overriding the method getCustomChannels()
:
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Andrea Marco Sartori
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of notifiable-exception with dependencies
illuminate/support Version ^5.5|^6.0|^7.0
illuminate/contracts Version ^5.5|^6.0|^7.0
illuminate/notifications Version ^5.5|^6.0|^7.0
illuminate/bus Version ^5.5|^6.0|^7.0