26

I want to know what events are fired by Laravel core libraries. I want to get the complete list, such as laravel.query and laravel.done.

There are four events listed at the official docs, but I think Laravel has more events than these four!

Cœur
  • 37,241
  • 25
  • 195
  • 267
Omid Kamangar
  • 5,768
  • 9
  • 40
  • 69

4 Answers4

46

Laravel doesn't actually fire as many events as you'd think. While it does make use of the Event system it's there for developers to use within there applications. Anyway, here's a list I compiled.

laravel.done
laravel.log
laravel.query
laravel.resolving
laravel.composing: {viewname}
laravel.started: {bundlename}
laravel.controller.factory
laravel.config.loader
laravel.language.loader
laravel.view.loader
laravel.view.engine

view.filter

eloquent.saving
eloquent.updated
eloquent.created
eloquent.saved
eloquent.deleting
eloquent.deleted
eloquent.booted: {$model}
eloquent.booting: {$model}


500
404

The 500 and 404 are both error related events. These are set in the routes.php file so you can see what the default listener is.

I'd like to point out that the eloquent.{event} have another variation containing the class name that is being updated.

eloquent.{event}: {classname}

I'm not going to say this is absolutely everything but it should be at least 99% of it.

ArjanSchouten
  • 1,360
  • 9
  • 23
Jason Lewis
  • 18,537
  • 4
  • 61
  • 64
  • 1
    It's worth noting that as of 5.4, some of the above have either been renamed or removed. I was looking for something similar to the `laravel.done` event but struggled to find any documentation. I recommend just listening out for all events with `*` and logging the event dispatcher instance passed in to get a feel for what's available. – Bower Mar 10 '17 at 14:18
19

In addition to Jason Lewis answer, I have few more to add. I simply searched for fire() function and came up with following list for Laravel 5,

$this->events->fire('auth.attempt', $payload);
$this->events->fire('auth.login', [$user, $remember]);
$this->events->fire('auth.logout', [$user]);
$this->events->fire('cache.'.$event, $payload);
$this->laravel['events']->fire('cache:clearing', [$storeName]);
$this->laravel['events']->fire('cache:cleared', [$storeName]);
$events->fire('artisan.start', [$this]);
$this->events->fire('illuminate.query', array($query, $bindings, $time, $this->getName()));
$this->events->fire('connection.'.$this->getName().'.'.$event, $this);
$this['events']->fire('bootstrapping: '.$bootstrapper, [$this]);
$this['events']->fire('bootstrapped: '.$bootstrapper, [$this]);
$this['events']->fire('locale.changed', array($locale));
$this['events']->fire($class = get_class($provider), array($provider));  //after provider registered.
$this->app['events']->fire('kernel.handled', [$request, $response]);
$this->dispatcher->fire('illuminate.log', compact('level', 'message', 'context'));
$this->events->fire('mailer.sending', array($message));
$this->events->fire('illuminate.queue.failed', array($connection, $job, $data));
$this->events->fire('illuminate.queue.stopping');
$this->events->fire('router.matched', [$route, $request]);
$this->events->fire('composing: '.$view->getName(), array($view));
$this->events->fire('creating: '.$view->getName(), array($view));
pinkal vansia
  • 10,240
  • 5
  • 49
  • 62
4

If you are debugging your Laravel application, you can get a full list of fired events in the console (for example when you are running unit tests or an artisan command) for the running process with the following snippet:

Event::listen('*', function ($event) {
    echo $event."\n";
});

If you use the logger function it would go to an infinite loop.

Amirmasoud
  • 590
  • 4
  • 11
  • 27
3

Here are a few of them more, got them while dumping static::$events

laravel.config.loader
laravel.view.loader
laravel.language.loader
laravel.view.engine
404

Not really sure if overriding these would work, as they are internally called

Akash
  • 4,956
  • 11
  • 42
  • 70
  • You can actually listen for these and define your own custom loaders. This is great if you want a cascading loading system for configuration/view/language files. I've done this occasionally. – Jason Lewis Oct 25 '12 at 05:27