In event-driven architecture, events act as signals. Listeners react to these signals independently. This means the event doesn't need to know which listeners exist or what they do. This separation reduces direct dependencies, making the code easier to maintain and extend.
When an event is fired in Laravel, the framework automatically calls all listeners registered for that event. The event itself does not manage or know about the listeners, which supports decoupling.
<?php // Event: UserRegistered // Listeners: // SendWelcomeEmail writes 'Welcome email sent.' // LogRegistration writes 'User registration logged.' // When event UserRegistered is fired // What appears in the log?
When the UserRegistered event fires, Laravel calls all listeners in the order they are registered. Both listeners write their messages, so the log contains both lines in sequence.
protected $listen = [
UserRegistered::class => [
SendWelcomeEmail::class,
],
];Laravel expects the listeners for an event to be an array. Option A assigns a single class without an array, causing a syntax or runtime error.
class EventServiceProvider extends ServiceProvider { protected $listen = [ UserRegistered::class => [ SendWelcomeEmail::class, ], ]; public function boot() { // Missing parent::boot(); } } // Event fired somewhere: // event(new UserRegistered($user));
In Laravel, the EventServiceProvider's boot method should call parent::boot() to register the event listeners. Omitting this call means listeners won't be registered and won't run.