Complete the code to register an event subscriber class in Laravel's EventServiceProvider.
protected $subscribe = [[1]::class];
In Laravel, event subscribers are registered by listing their class names in the $subscribe array in the EventServiceProvider.
Complete the method name in the subscriber class to listen for the UserRegistered event.
public function [1](UserRegistered $event) {
// handle the event
}Subscriber methods that handle events usually start with 'on' followed by the event name in Laravel.
Fix the error in the subscriber's subscribe method to register the event handler.
public function subscribe(Dispatcher $events) {
$events->listen(
UserRegistered::class,
[[1]::class, 'onUserRegistered']
);
}The subscriber class itself is passed as the first element in the listener array to register the handler method.
Fill both blanks to define the subscribe method and register two event handlers in the subscriber class.
public function subscribe(Dispatcher $events) {
$events->listen(UserRegistered::class, [[1]::class, 'onUserRegistered']);
$events->listen(UserLoggedIn::class, [[2]::class, 'onUserLoggedIn']);
}Both event handlers are methods inside the same subscriber class, so the class name is repeated.
Fill all three blanks to create a subscriber class with the subscribe method registering handlers for three events.
class UserEventSubscriber { public function subscribe(Dispatcher $events) { $events->listen(UserRegistered::class, [[1]::class, 'onUserRegistered']); $events->listen(UserLoggedIn::class, [[2]::class, 'onUserLoggedIn']); $events->listen(UserLoggedOut::class, [[3]::class, 'onUserLoggedOut']); } }
The subscriber class registers all event handlers using its own class name in the subscribe method.