Laravel Notification Event Subscriber Package
Published on by Paul Redmond
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:
use Illuminate\Support\Facades\Log; class UserRegisteredNotification extends Notification{ /* ...Notification code... */ // Handlers for sending/sent events. public function onSending(string $channel, $response = null): void { Log::info($this::class . ' is being sent via ' . $channel); } public function onSent(string $channel): void { Log::info($this::class . ' has been sent via ' . $channel); }}
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.