如何关闭 Spatie 备份中的通知。
我创建了一个命令来每天运行备份,但我想停止有关成功和失败的通知,我在备份配置文件中评论了通知:
'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' => '[email protected]',
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'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' => '',
],
],
即使我评论了所有块,但是当我运行
php artisan backup:run
时,它备份成功,但继续尝试发送通知。
我找到了一个解决方案,即php artisan backup:run --disable-notifications
,但我在计划中使用备份,并且无法在$schedule->command('backup:run')->daily();
中添加参数,我尝试了$schedule->command('backup:run --disable-notifications')->daily();
,并且在签名中尝试了protected $signature = 'db:backup --only-db --disable-notifications';
,但两者都不起作用
要停止发送通知,只需为通知类声明一个空数组即可。
从
['mail']
到[]
。
因此,如果您想禁用所有事件的通知,您的
notifications
数组应如下所示:
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => [],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFoundNotification::class => [],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailedNotification::class => [],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessfulNotification::class => [],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFoundNotification::class => [],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessfulNotification::class => [],
],
P。 S. 您可能希望在备份尝试失败时留下通知,以便在出现问题时您会收到通知:
\Spatie\Backup\Notifications\Notifications\BackupHasFailedNotification::class => ['mail'],