Discover all events fired in one request

If you want to implement a new listener to a specific event but you don't know its name, you can log all events fired during the request.

You can use the \Illuminate\Support\Facades\Event::listen() method on boot() method of app/Providers/EventServiceProvider.php to catch all events fired.

Important: If you use the Log facade within this event listener then you will need to exclude events named Illuminate\Log\Events\MessageLogged to avoid an infinite loop. (Example: if ($event == 'Illuminate\\Log\\Events\\MessageLogged') return;)

// Include Event...
use Illuminate\Support\Facades\Event;
 
// In your EventServiceProvider class...
public function boot()
{
parent::boot();
Event::listen('*', function ($event, array $data) {
// Log the event class
error_log($event);
// Log the event data delegated to listener parameters
error_log(json_encode($data, JSON_PRETTY_PRINT));
});
}

Tip given by @MuriloChianfa

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 79 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials