LaravelLaravel19 min read

Events and Listeners: Decoupling Application Logic

Learn how to trigger events and react to them using listeners for clean, maintainable architecture.

Steven Brown
November 6, 2025
5.5k159

As applications grow, placing all logic in controllers becomes messy. Events help separate concerns.

  Example:
  When a user registers:
  - Send welcome email
  - Create profile
  - Notify admin
  
  All without cluttering the controller.
  
  ## Create event and listener
  
  ```bash
  php artisan make:event UserRegistered
  php artisan make:listener SendWelcomeEmail --event=UserRegistered
  ```
  
  ## Fire event
  
  ```php
  event(new UserRegistered($user));
  ```
  
  ## Listener handle
  
  ```php
  public function handle(UserRegistered $event) {
    Mail::to($event->user->email)->send(new WelcomeMail());
  }
  ```
  
  ## Event flow
  
  ```mermaid
  flowchart TD
    A[Action Occurs] --> B[Event Fired]
    B --> C[Listener 1]
    B --> D[Listener 2]
    B --> E[Listener 3]
  ```
  
  Events make large systems easier to extend.
  
  In the next tutorial, we will move heavy work into background queues.
#Laravel#Architecture#Advanced