tkaratug/laravel-notification-event-subscriber

这是我制作的包:laravel-notification-event-subscriber

1.3.0 2023-02-19 14:49 UTC

This package is auto-updated.

Last update: 2024-09-19 18:01:52 UTC


README

image

Laravel 通知事件订阅者

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

此包允许您使用 onSent()onSending() 方法在发送通知时或发送后运行任何类型的操作。

它注册了一个事件订阅者 NotificationEventSubscriber 并监听 Laravel 的 NotificationSentNotificationSending 事件。当其中一个被触发时,事件订阅者根据事件执行定义的方法。

安装

您可以通过 composer 安装此包

composer require tkaratug/laravel-notification-event-subscriber

用法

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Log;

class UserRegisteredNotification extends Notification
{   
    public function via($notifiable): array
    {
        return ['mail'];
    }
    
    public function toMail($notifiable): MailMessage
    {
        return (new MailMessage)
                    ->greeting('foo')
                    ->line('bar');
    }
    
    public function onSending($notifiable, $channel, $response = null): void
    {
        Log::info($this::class . ' is being sent to  via ' . $channel);
    }
    
    public function onSent($notifiable, $channel): void
    {
        Log::info($this::class . ' has been sent to  via ' . $channel);
    }
}

测试

composer test

变更日志

请参阅 变更日志 了解最近的变化。

贡献

请参阅 贡献指南 了解详细信息。

安全漏洞

请查看 我们的安全策略 了解如何报告安全漏洞。

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件