0
0
Laravelframework~10 mins

Event dispatching in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to dispatch an event named UserRegistered.

Laravel
event(new [1]());
Drag options to blanks, or click blank then click option'
AUserUpdated
BUserCreated
CUserRegistered
DUserLogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using an event class name that does not exist.
Forgetting to use the new keyword before the event class.
2fill in blank
medium

Complete the code to listen for the UserRegistered event in the EventServiceProvider.

Laravel
'UserRegistered' => [[1]::class],
Drag options to blanks, or click blank then click option'
ALogUserLogin
BSendWelcomeEmail
CUpdateUserStats
DNotifyAdmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using a listener that does not relate to the event.
Forgetting to add ::class after the listener name.
3fill in blank
hard

Fix the error in dispatching the event using the Event facade.

Laravel
Event::[1](new UserRegistered($user));
Drag options to blanks, or click blank then click option'
Adispatch
Bsend
Cfire
Dtrigger
Attempts:
3 left
💡 Hint
Common Mistakes
Using deprecated or incorrect method names like fire.
Confusing event dispatching with other actions.
4fill in blank
hard

Fill both blanks to create an event listener class that handles UserRegistered event.

Laravel
public function handle([1] $event)
{
    [2];
}
Drag options to blanks, or click blank then click option'
AUserRegistered
B$event->user->sendWelcomeEmail()
C$event->sendNotification()
DUserLogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong event class in the handle method parameter.
Calling a method that does not exist on the event object.
5fill in blank
hard

Fill all three blanks to dispatch a queued event with delay.

Laravel
UserRegistered::[1]()->delay(now()->addMinutes([2]))->[3]();
Drag options to blanks, or click blank then click option'
Adispatch
B10
CdispatchSync
DdispatchAfterResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous dispatch when queuing is intended.
Forgetting to specify delay time as a number.
Confusing dispatch methods.