Laravel - Notifications - Notification Sent Event
When a notification is sent, the Illuminate\Notifications\Events\NotificationSent
event is dispatched by the notification system. This contains the "notifiable" entity and the notification instance itself. You may register listeners for this event in your EventServiceProvider
:
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'Illuminate\Notifications\Events\NotificationSent' => [
'App\Listeners\LogNotification',
],
];
After registering listeners in yourEventServiceProvider
, use theevent:generate
Artisan command to quickly generate listener classes.
Within an event listener, you may access the notifiable
, notification
, channel
, and response
properties on the event to learn more about the notification recipient or the notification itself:
/**
* Handle the event.
*
* @param \Illuminate\Notifications\Events\NotificationSent $event
* @return void
*/
public function handle(NotificationSent $event)
{
// $event->channel
// $event->notifiable
// $event->notification
// $event->response
}