Laravel Notification Occasion Subscriber is an easy bundle that registers an occasion subscriber to make it straightforward to run code whereas sending notifications.
Particularly, this bundle lets you run any motion whereas a notification is being despatched or after it has been despatched:
1use IlluminateSupportFacadesLog;
2
3class UserRegisteredNotification extends Notification
4{
5 /* ...Notification code... */
6
7 // Handlers for sending/despatched occasions.
8 public operate onSending(string $channel, $response = null): void
9 {
10 Log::data($this::class . ' is being despatched through ' . $channel);
11 }
12
13 public operate onSent(string $channel): void
14 {
15 Log::data($this::class . ' has been despatched through ' . $channel);
16 }
17}
It really works by registering an occasion subscriber that listens to the NotificationSending
and NotificationSent
occasions, which checks to see if the notification class defines an onSending
or onSent
methodology.
If you would like to be taught extra about this bundle, test it out on GitHub at laravel-notification-event-subscriber.