Blog Detail


Run Any Kind of Action in Laravel while Notification is Sent cover image

arrow_back Run Any Kind of Action in Laravel while Notification is Sent

Laravel Notification Event Subscriber is a package allows you to run any kind of action while a notification is being sent or after it has been sent using onSent() and onSending() methods.

It registers an event subscriber NotificationEventSubscriber and listens to the NotificationSent and NotificationSending events of Laravel. When one of them is fired, the event subscriber runs a defined method according to the event.


You can install the package via 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)
    public function onSending($channel): void
        Log::info($this::class . ' is being sent via ' . $channel);        
    public function onSent($channel): void
        Log::info($this::class . ' has been sent via ' . $channel);

Closing Note

Codebrisk is here to help you grow your business. Our expert developers have plenty of experience in Laravel Custom Web Application Development. We can enhance the performance of applications with easy syntax, third-party API integrations, and built-in functions, followed by a high level of security to prevent unauthorized access to data. We always provide a customized website solution tailored to our client’s needs. So if you’re interested, you can get in touch with us or get a free quote from us.

Published at : 16-09-2022

Author : Rizwan Aslam
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project