Primo Committ

This commit is contained in:
paoloar77
2024-05-07 12:17:25 +02:00
commit e73d0e5113
7204 changed files with 884387 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
---
title: Sending notifications
weight: 4
---

View File

@@ -0,0 +1,62 @@
---
title: Adding extra notification channels
weight: 2
---
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 [http://laravel-notification-channels.com](http://laravel-notification-channels.com).
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
```php
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:
```php
namespace App\Notifications;
use Spatie\Backup\Notifications\Notifications\BackupHasFailed 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.
```php
// config/backup.php
use \NotificationChannels\PusherPushNotifications\Channel as PusherChannel
...
'notifications' => [
'notifications' => [
\App\Notifications\BackupHasFailed::class => ['mail', 'slack', PusherChannel::class],
...
```

View File

@@ -0,0 +1,40 @@
---
title: Customizing the notifiable
weight: 3
---
Laravel's notifications are sent to a notifiable. A notifiable provides configuration values that determine how notifications will be sent.
By default the package uses this notifiable class: `\Spatie\Backup\Notifications\Notifiable`. This class will read out the config file. All mail notifications will be sent to the mail address specified in the `notifications.mail.to` key of the config file.
If you use a channel that needs some get some extra information out of the notifiable you can easily extend the default notifiable.
Here's how that might look like:
```php
namespace App\Notifications;
use Spatie\Backup\Notifications\Notifiable;
class BackupNotifiable extends Notifiable
{
public function routeNotificationForAnotherNotificationChannel()
{
return config('backup.notifications.another_notification_channel.property');
}
}
```
Don't forget to register the notifiable in the config file:
```php
// config/backup.php
'notifications' => [
...
'notifiable' => App\Notifications\BackupNotifiable::class,
```

View File

@@ -0,0 +1,64 @@
---
title: Sending notifications
weight: 1
---
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 and Slack (for Slack you'll need to require `laravel/slack-notification-channel` in your project).
## Configuration
This is the portion of the configuration that will determine when and how notifications will be sent.
```php
//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\Events` classes.
*/
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::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,
],
],
```