Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to dispatch a job called SendEmail.
Laravel
<?php
use App\Jobs\SendEmail;
SendEmail::[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
run() or execute() which are not Laravel job dispatch methods.Trying to call
send() which is not a job dispatch method.✗ Incorrect
In Laravel, you dispatch a job by calling the static method
dispatch() on the job class.2fill in blank
mediumComplete the code to dispatch a job ProcessOrder with an order ID of 123.
Laravel
<?php
use App\Jobs\ProcessOrder;
ProcessOrder::dispatch([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an array instead of a single value.
Passing a string key-value pair instead of just the ID.
✗ Incorrect
You pass the order ID directly as an argument to the job's dispatch method if the constructor expects it.
3fill in blank
hardFix the error in dispatching a job GenerateReport synchronously.
Laravel
<?php
use App\Jobs\GenerateReport;
GenerateReport::[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
dispatch() which queues the job asynchronously.Using
dispatchNow() which is deprecated in newer Laravel versions.✗ Incorrect
To dispatch a job synchronously in Laravel, use
dispatchSync() method.4fill in blank
hardFill both blanks to dispatch a job UpdateUserProfile with user ID 42 and delay it by 10 minutes.
Laravel
<?php use App\Jobs\UpdateUserProfile; UpdateUserProfile::[1](42)->[2](now()->addMinutes(10));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
dispatchSync which runs immediately, ignoring delay.Using
run which is not a Laravel method.✗ Incorrect
Use
dispatch to send the job to the queue and delay to postpone execution.5fill in blank
hardFill all three blanks to dispatch a job SendNotification with message, user ID, and priority, and chain it with LogNotification job.
Laravel
<?php use App\Jobs\SendNotification; use App\Jobs\LogNotification; SendNotification::[1]('Hello', 7, 'high')->[2](new LogNotification())->[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
send which is not a Laravel job dispatch method.Using
dispatchSync which runs immediately and ignores chaining.✗ Incorrect
Use
dispatch to create the PendingDispatch with parameters, chain to link jobs, and dispatch to queue them.