Adding extra notification channels | laravel-backup | Spatie

 SPATIE

  Laravel Backup
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup](https://spatie.be/docs/laravel-backup/v7)  Sending-notifications  Adding extra notification channels

 Version   v10   v9   v8   v7   v6   v5   v4   v3

 Other versions for crawler [v10](https://spatie.be/docs/laravel-backup/v10) [v9](https://spatie.be/docs/laravel-backup/v9) [v8](https://spatie.be/docs/laravel-backup/v8) [v7](https://spatie.be/docs/laravel-backup/v7) [v6](https://spatie.be/docs/laravel-backup/v6) [v5](https://spatie.be/docs/laravel-backup/v5) [v4](https://spatie.be/docs/laravel-backup/v4) [v3](https://spatie.be/docs/laravel-backup/v3)

- [ Introduction ](https://spatie.be/docs/laravel-backup/v7/introduction)
- [ Support us ](https://spatie.be/docs/laravel-backup/v7/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-backup/v7/requirements)
- [ High level overview ](https://spatie.be/docs/laravel-backup/v7/high-level-overview)
- [ Installation and setup ](https://spatie.be/docs/laravel-backup/v7/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/laravel-backup/v7/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup/v7/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup/v7/about-us)

Taking Backups
--------------

- [ Taking backups ](https://spatie.be/docs/laravel-backup/v7/taking-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup/v7/taking-backups/events)

Cleaning up old backups
-----------------------

- [ Cleaning up old backups ](https://spatie.be/docs/laravel-backup/v7/cleaning-up-old-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup/v7/cleaning-up-old-backups/events)

Monitoring the health of all backups
------------------------------------

- [ Monitoring the health of all backups ](https://spatie.be/docs/laravel-backup/v7/monitoring-the-health-of-all-backups/overview)
- [ Creating your custom health check ](https://spatie.be/docs/laravel-backup/v7/monitoring-the-health-of-all-backups/creating-your-custom-health-check)
- [ Events ](https://spatie.be/docs/laravel-backup/v7/monitoring-the-health-of-all-backups/events)

Sending notifications
---------------------

- [ Sending notifications ](https://spatie.be/docs/laravel-backup/v7/sending-notifications/overview)
- [ Adding extra notification channels ](https://spatie.be/docs/laravel-backup/v7/sending-notifications/adding-extra-notification-channels)
- [ Customizing the notifiable ](https://spatie.be/docs/laravel-backup/v7/sending-notifications/customizing-the-notifiable)

Advanced Usage
--------------

- [ Adding extra files to a backup ](https://spatie.be/docs/laravel-backup/v7/advanced-usage/adding-extra-files-to-a-backup)
- [ Backing up a non-laravel application ](https://spatie.be/docs/laravel-backup/v7/advanced-usage/backing-up-a-non-laravel-application)
- [ Binary database dumps with PostgreSQL ](https://spatie.be/docs/laravel-backup/v7/advanced-usage/binary-database-dumps-with-postgresql)
- [ Encrypt backup archives ](https://spatie.be/docs/laravel-backup/v7/advanced-usage/encrypt-backup-archives)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-backup                                                                                                                                                                                                                                    `

Adding extra notification channels
==================================

By default the package send notifications via email or Slack. It's easy to add an extra notification channel such as Telegram or native mobile push notification, etc.

The Laravel community is awesome. Shortly after Laravel 5.3 was released various developers worked together to create 30+ notification channels. You can view them all on .

In the following example we're going to add the Pusher push notifications channel. Other notification drivers can be added in the same way.

### 1. Install the notification channel driver

For Pusher Push notifications, require this package

```
laravel-notification-channels/pusher-push-notifications
```

After composer has pulled in the package, just follow [the installation instructions of the package](https://github.com/laravel-notification-channels#installation) to complete the installation.

### 2. Creating your own custom notification

Let say you want to be notified via Pusher push notifications when a backup fails. To make this happen you'll need to create your own `BackupFailed` notification class like the one below:

```
namespace App\Notifications;

use Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification as BaseNotification;
use NotificationChannels\PusherPushNotifications\Message;

class BackupHasFailed extends BaseNotification
{
    public function toPushNotification($notifiable)
    {
        return Message::create()
            ->iOS()
            ->badge(1)
            ->sound('fail')
            ->body("The backup of {$this->applicationName()} to disk {$this->diskName()} has failed");
    }
}
```

### 3. Register your custom notification in the config file

The last thing you need to do is register your custom notification in the config file.

```
// config/backup.php
use \NotificationChannels\PusherPushNotifications\Channel as PusherChannel

...

    'notifications' => [

        'notifications' => [
            \App\Notifications\BackupHasFailed::class => ['mail', 'slack', PusherChannel::class],
            ...
```
