Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a notification using the queue.
Laravel
$user->notify(new [1](new InvoicePaid($invoice))); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the notification class name as a string instead of an instance.
Using a wrong notification class.
✗ Incorrect
You need to pass the notification class instance, here InvoicePaid, to the notify method.
2fill in blank
mediumComplete the code to make the notification queueable.
Laravel
class InvoicePaid extends Notification implements [1] { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using traits instead of interfaces to queue notifications.
Forgetting to implement ShouldQueue.
✗ Incorrect
Implementing ShouldQueue interface tells Laravel to queue the notification.
3fill in blank
hardFix the error in the code to dispatch the notification to the queue.
Laravel
Notification::send($users, (new InvoicePaid($invoice))->[1]()); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendNow() which sends immediately without queue.
Calling notify() which is not a method on notification instances.
✗ Incorrect
Calling queue() on the notification instance dispatches it to the queue.
4fill in blank
hardFill both blanks to delay a queued notification by 10 minutes.
Laravel
return (new InvoicePaid($invoice))->[1](now()->addMinutes(10))->[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling send() instead of queue(), which sends immediately.
Not chaining delay() before queue().
✗ Incorrect
delay() sets the delay time, queue() dispatches the notification to the queue.
5fill in blank
hardFill all three blanks to configure a notification to use a specific queue and connection.
Laravel
return (new InvoicePaid($invoice))->onConnection([1])->onQueue([2])->[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using send() instead of queue(), which sends immediately.
Passing connection or queue names without quotes.
✗ Incorrect
onConnection() sets the queue connection, onQueue() sets the queue name, queue() dispatches the notification.