Skip to main content

What are events?

Laravel’s event system implements the observer pattern. When something notable happens in your application—an order ships, a user registers—you dispatch an event. One or more listeners respond to that event independently. This decouples your core business logic from side effects like sending emails or updating analytics. You can add, remove, or change listeners without touching the code that raised the event.

Generating events and listeners

Use Artisan to scaffold events and listeners:
Running the commands without arguments prompts you interactively for names.

Registering events and listeners

Event discovery (automatic)

By default, Laravel scans app/Listeners automatically and registers any listener method that begins with handle or __invoke. The event it listens to is determined by the type-hint in the method signature:
No manual registration needed. Cache the manifest before deploying to production:

Manual registration

Register events manually inside AppServiceProvider::boot using the Event facade:

Closure listeners

Register a closure directly for lightweight, one-off reactions:

Defining events

An event is a data container. It holds the information needed by listeners—nothing more:
SerializesModels ensures Eloquent models serialize correctly when the event is used with a queued listener.

Defining listeners

Listeners receive the event in their handle method. The service container injects any constructor dependencies automatically:
Return false from handle to stop the event from propagating to other listeners.

Dispatching events

Call dispatch on the event class:
Dispatch after the current database transaction commits, so listeners only run when the data is actually saved:

Queued listeners

Listeners that send emails or call external APIs should run in the background. Implement ShouldQueue to push the listener onto the queue automatically:
Customize the queue connection and name:

Debouncing event listeners

When the same event is dispatched repeatedly for a short period, you may want to handle only the latest instance. Add the DebounceFor attribute to a queued listener to debounce events within the specified period:
In this example, repeatedly dispatching ProductUpdated events for the same product within 30 seconds debounces the listener so that only the latest event is handled. Events with different debounce IDs are handled independently. To cap how long a frequently dispatched event can defer a listener, provide the maxWait argument:
Customize the cache store used for debounce tracking with a debounceVia method. The method receives the event and should return a cache repository:
Debounced and unique listeners are mutually exclusive. A listener using DebounceFor should not implement ShouldBeUnique. If events are dispatched from multiple web servers or containers, ensure they all use the same shared cache server.

Queueable closure listeners

Wrap a closure with queueable to run it on the queue:

Event subscribers

An event subscriber is a single class that handles multiple events. Implement a subscribe method and register the class:
Register the subscriber in AppServiceProvider::boot:

End-to-end example

1

Create the event

2

Create the listener

3

Dispatch from the controller

Testing events

Fake all events to assert they were dispatched without triggering listeners:

Queues

Learn how to run queued listeners and background jobs at scale.
Last modified on August 18, 2026