An event is really just the implementation of a broadcast/receiver pattern. Events are listened for by the receivers, and events are fired by the broadcasters.

Basic Examples #

// Listen for an event
Event::listen('log-ip', function($ip){
    // Do something with the ip

// Fire an event
Event::fire('log-ip', Request::ip());

// Call a class/method rather than a closure function
Event::listen('user-updated', 'App\service\User@wasUpdated');

// Fire it
Event::fire('user-updated', [$user_id,$user_name]);

Event priority #

Any number of receivers can listen to a specific event. To specify the priority of your receiver pass an integer value as the third argument to listen(). By default the priority is set to 0 (lower is higher priority), and collisions cause escalation up until an open slot is found.

// Receivers with priorities
Event::listen('log-visitor', 'Visitor@logHit',20);
Event::listen('log-visitor', 'Visitor@wasNefarious',10);

// Fire it
// @wasNefarious will be called first
// @logHit will be called second
Event::fire('log-visitor', Request::ip());