• Reading time ~ 1 min
  • 21.02.2023

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.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297