Sending notifications | laravel-backup | Spatie

 SPATIE

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup](https://spatie.be/docs/laravel-backup/v10)  Sending-notifications  Sending notifications

 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/v10/introduction)
- [ Support us ](https://spatie.be/docs/laravel-backup/v10/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-backup/v10/requirements)
- [ High level overview ](https://spatie.be/docs/laravel-backup/v10/high-level-overview)
- [ Installation and setup ](https://spatie.be/docs/laravel-backup/v10/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/laravel-backup/v10/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup/v10/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup/v10/about-us)

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

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

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

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

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

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

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

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

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

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

 Sending notifications
=====================

###  On this page

1. [ Configuration ](#content-configuration)

The package leverages Laravel's native notifications to let you know that your backups are ok, or not. Out of the box it can send notifications via mail, Slack (for Slack you'll need to require `laravel/slack-notification-channel` in your project), Discord, and a generic webhook channel (useful for Mattermost, Microsoft Teams, or custom integrations).

Configuration
-----------------------------------------------------------------------------------------------

This is the portion of the configuration that will determine when and how notifications will be sent.

```
//config/backup.php

    /*
     * You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'.
     * For Slack you need to install laravel/slack-notification-channel.
     *
     * You can also use your own notification classes, just make sure the class is named after one of
     * the `Spatie\Backup\Notifications\Notifications` classes.
     */
    'notifications' => [
        'notifications' => [
            \Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['mail'],
            \Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFoundNotification::class => ['mail'],
            \Spatie\Backup\Notifications\Notifications\CleanupHasFailedNotification::class => ['mail'],
            \Spatie\Backup\Notifications\Notifications\BackupWasSuccessfulNotification::class => ['mail'],
            \Spatie\Backup\Notifications\Notifications\HealthyBackupWasFoundNotification::class => ['mail'],
            \Spatie\Backup\Notifications\Notifications\CleanupWasSuccessfulNotification::class => ['mail'],
        ],

        /*
         * Here you can specify the notifiable to which the notifications should be sent. The default
         * notifiable will use the variables specified in this config file.
         */
        'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,

        'mail' => [
            'to' => 'your@example.com',

            'from' => [
                'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
                'name' => env('MAIL_FROM_NAME', 'Example'),
            ],
        ],

        'slack' => [
            'webhook_url' => '',

            /*
             * If this is set to null the default channel of the webhook will be used.
             */
            'channel' => null,

            'username' => null,

            'icon' => null,
        ],

        'discord' => [
            'webhook_url' => '',

            /*
             * If this is an empty string, the name field on the webhook will be used.
             */
            'username' => '',

            /*
             * If this is an empty string, the avatar on the webhook will be used.
             */
            'avatar_url' => '',
        ],

        /*
         * A generic webhook channel that POSTs JSON to a URL.
         * Useful for Mattermost, Microsoft Teams, or custom integrations.
         */
        'webhook' => [
            'url' => '',
        ],
    ],
```
