Laravel0Laravel Notification Event Subscriber Package

[ad_1]

Laravel Notification Event Subscriber is a simple package that registers an event subscriber to make it easy to run code while sending notifications.

Specifically, this package allows you to run any action while a notification is being sent or after it has been sent:

1use Illuminate\Support\Facades\Log;

2 

3class UserRegisteredNotification extends Notification

4{

5 /* ...Notification code... */

6 

7 // Handlers for sending/sent events.

8 public function onSending(string $channel, $response = null): void

9 {

10 Log::info($this::class . ' is being sent via ' . $channel);

11 }

12 

13 public function onSent(string $channel): void

14 {

15 Log::info($this::class . ' has been sent via ' . $channel);

16 }

17}

It works by registering an event subscriber that listens to the NotificationSending and NotificationSent events, which checks to see if the notification class defines an onSending or onSent method.

If you’d like to learn more about this package, check it out on GitHub at laravel-notification-event-subscriber.

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *