What are Events and Listeners in Laravel?
Why Interviewers Ask This
Mid-level Laravel roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
Laravel's event system implements the Observer pattern, providing a way to decouple various aspects of your application. Create an event: php artisan make:event UserRegistered. Create a listener: php artisan make:listener SendWelcomeEmail --event=UserRegistered. Register in EventServiceProvider: protected $listen = [UserRegistered::class => [SendWelcomeEmail::class]]. Fire the event: event(new UserRegistered($user)) or UserRegistered::dispatch($user). Listeners can be queued by implementing ShouldQueue. Model events fire automatically: creating, created, updating, updated, deleting, deleted, saved, restored. Use php artisan event:list to see all registered events and listeners.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Laravel codebase.