Events & listeners
Decouple domain actions from notifications and integrations.
Events decouple side effects from domain actions. Dispatch when something meaningful happens; listen when another module should react.
Dispatch
phpapp/Services/ProjectService.php
event(new ProjectCreated($project));Listen
phpapp/Listeners/SendProjectWelcomeMail.php
class SendProjectWelcomeMail
{
public function handle(ProjectCreated $event): void
{
Mail::to($event->project->owner)->queue(
new ProjectWelcomeMail($event->project)
);
}
}When to use events
| Situation | Prefer | Avoid |
|---|---|---|
| Notify other modules | Events | Fat controllers |
| Must succeed with the write | Same transaction | Async listener |
| Best-effort side effect | Queued listener | Blocking mail |
Info
Queued listeners inherit job failure handling. Pair them with failed job alerts in production.
- Name events in the past tense (ProjectCreated).
- Keep payloads serializable.
- Register listeners in EventServiceProvider or attributes.
Updated Aug 5, 2026
