Laravel Listener Pattern Skill
Use this skill when implementing Event-Driven Architecture.
Workflow
-
Create Event: php artisan make:event [EventName]
-
Create Listener: php artisan make:listener [ListenerName] --event=[EventName]
Rules
- Queued Listeners
- If the listener performs IO (Email, API, Notification), it MUST implement ShouldQueue .
class SendWelcomeEmail implements ShouldQueue { // ... }
- Dependency Injection
-
Inject dependencies in __construct .
-
Access event data in handle(EventName $event) .
- Verification
- Ensure the mapping exists. Laravel 11/12 detects it automatically if the listener type-hints the event.