๐Ÿ“ก Events & Listeners

Event fired โ†’ Listener handles โ†’ logged to storage/logs/laravel-2026-06-21.log (channel: daily)

Fire PostCreated Event

Will fire for: Test (Post #8)

Listener: LogPostCreated โ†’ writes to log.

// Event class

class PostCreated {

  use Dispatchable, SerializesModels;

  public function __construct(

    public readonly Post $post

  ) {}

}

// Listener

class LogPostCreated {

  public function handle(PostCreated $e): void

  { Log::info('[Event] ...'); }

}

// Wired in bootstrap/app.php:

Event::listen(PostCreated::class, LogPostCreated::class);