0
0
Laravelframework~10 mins

Creating jobs in Laravel - Interactive Practice

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

Complete the code to create a new job class using Artisan.

Laravel
php artisan [1] MakeEmailJob
Drag options to blanks, or click blank then click option'
Amake:job
Bmake:controller
Cmake:model
Dmake:migration
Attempts:
3 left
💡 Hint
Common Mistakes
Using make:controller instead of make:job
Using make:model which creates a model, not a job
Using make:migration which creates a database migration
2fill in blank
medium

Complete the code to dispatch a job named SendWelcomeEmail.

Laravel
SendWelcomeEmail::[1]();
Drag options to blanks, or click blank then click option'
Aexecute
Bhandle
Crun
Ddispatch
Attempts:
3 left
💡 Hint
Common Mistakes
Calling handle() directly instead of dispatch()
Using run() or execute() which are not Laravel job dispatch methods
3fill in blank
hard

Fix the error in the job class constructor to accept a User model.

Laravel
public function __construct([1] $user)
{
    $this->user = $user;
}
Drag options to blanks, or click blank then click option'
AUser
Buser
CuserModel
DUserModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'user' which is a variable, not a type
Using incorrect class names like UserModel
4fill in blank
hard

Fill both blanks to define the job's queue connection.

Laravel
public $[1] = '[2]';
Drag options to blanks, or click blank then click option'
Aconnection
Bqueue
Cdefault
Demails
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'queue' property with 'connection'
Using incorrect values like 'emails' for connection
5fill in blank
hard

Fill the blanks to create a job class with a handle method that logs a message.

Laravel
class LogJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        [1]::info([2]);
    }
}
Drag options to blanks, or click blank then click option'
ALog
B'Job executed successfully'
CLogger
D'Job failed'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Logger instead of Log facade
Logging incorrect messages or missing quotes