Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of Laravel's scheduler?
Laravel's scheduler allows you to define scheduled tasks inside your application code instead of managing separate cron entries. It helps automate repetitive tasks like sending emails or cleaning databases.
Click to reveal answer
beginner
How do you register a scheduled task in Laravel?
You register scheduled tasks inside the <code>schedule()</code> method of the <code>App\Console\Kernel</code> class using methods like <code>->command()</code> or <code>->call()</code> with timing methods like <code>->daily()</code> or <code>->everyMinute()</code>.
Click to reveal answer
beginner
What is the cron entry you add to your server to run Laravel's scheduler?
You add a single cron entry that runs every minute: * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1. This triggers Laravel's scheduler to check and run due tasks.
Click to reveal answer
intermediate
How can you run a scheduled task only on weekdays in Laravel?
Use the weekdays() method in the scheduler chain. For example: $schedule->command('emails:send')->weekdays()->at('13:00'); runs the task at 1 PM Monday to Friday.
Click to reveal answer
intermediate
What is the benefit of using Laravel's scheduler over direct cron jobs for each task?
Laravel's scheduler centralizes task scheduling in code, making it easier to manage, test, and deploy. You only need one cron entry, reducing server complexity and risk of errors.
Click to reveal answer
What command does Laravel's scheduler run every minute via cron?
Aphp artisan schedule:run
Bphp artisan cron:run
Cphp artisan task:run
Dphp artisan schedule:execute
✗ Incorrect
The correct command is php artisan schedule:run, which Laravel uses to check and run scheduled tasks.
Where do you define scheduled tasks in a Laravel app?
AIn <code>routes/web.php</code>
BIn <code>App\Console\Kernel.php</code>
CIn <code>config/scheduler.php</code>
DIn <code>app/Http/Controllers/Scheduler.php</code>
✗ Incorrect
Scheduled tasks are defined in the schedule() method inside App\Console\Kernel.php.
How often should the cron job for Laravel scheduler run?
AEvery hour
BEvery day
CEvery minute
DEvery second
✗ Incorrect
The cron job runs every minute to check if any scheduled tasks are due.
Which method schedules a task to run daily at midnight?
A->daily()
B->hourly()
C->everyMinute()
D->weekly()
✗ Incorrect
The ->daily() method schedules a task to run once every day at midnight.
How do you schedule a task to run only on weekdays in Laravel?
A->monthly()
B->weekends()
C->daily()
D->weekdays()
✗ Incorrect
The ->weekdays() method restricts the task to run Monday through Friday.
Explain how Laravel's scheduler works with cron to automate tasks.
Think about how one cron job triggers Laravel to handle many tasks.
You got /4 concepts.
Describe how to define and schedule a command to run every day at 2 AM only on weekdays in Laravel.
Focus on the methods to set time and days in the scheduler.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Laravel's scheduler when using cron expressions?
easy
A. To create database migrations automatically
B. To manually execute commands from the terminal
C. To automate running tasks at specified times without manual intervention
D. To generate user authentication scaffolding
Solution
Step 1: Understand Laravel scheduler role
Laravel scheduler automates running tasks like commands or jobs at set times.
Step 2: Identify cron usage
Cron expressions define when tasks run automatically without manual input.
Final Answer:
To automate running tasks at specified times without manual intervention -> Option C
Quick Check:
Scheduler automates tasks [OK]
Hint: Scheduler automates tasks on schedule, not manual commands [OK]
Common Mistakes:
Confusing scheduler with manual command execution
Thinking scheduler creates migrations
Assuming scheduler generates UI code
2. Which of the following is the correct way to schedule a command to run every day at midnight in Laravel's app/Console/Kernel.php?
easy
A. $schedule->command('emails:send')->hourly();
B. $schedule->command('emails:send')->dailyAt('00:00');
C. $schedule->command('emails:send')->cron('0 12 * * *');
D. $schedule->command('emails:send')->everyMinute();
Solution
Step 1: Identify daily midnight syntax
Laravel's dailyAt('00:00') schedules a command at midnight daily.
Step 2: Check other options
everyMinute() runs every minute, cron('0 12 * * *') runs at noon, hourly() runs every hour.
Final Answer:
$schedule->command('emails:send')->dailyAt('00:00'); -> Option B
Quick Check:
dailyAt('00:00') = midnight daily [OK]
Hint: dailyAt('00:00') means every day at midnight [OK]
Common Mistakes:
Using cron('0 12 * * *') which runs at noon, not midnight
Confusing everyMinute() with daily scheduling
Using hourly() instead of dailyAt()
3. Given this scheduler code in app/Console/Kernel.php:
A. Minute value 60 is invalid; minutes range from 0 to 59
B. Hour value is missing
C. Day of month is invalid
D. Cron expression is missing the command name
Solution
Step 1: Check cron minute field
The first field is minute; valid values are 0 to 59. 60 is invalid.
Step 2: Confirm other fields
Other fields are valid, but minute 60 causes syntax error.
Final Answer:
Minute value 60 is invalid; minutes range from 0 to 59 -> Option A
Quick Check:
Minute must be 0-59, 60 is invalid [OK]
Hint: Minutes in cron go 0-59, never 60 [OK]
Common Mistakes:
Using 60 as minute value
Ignoring cron field ranges
Assuming missing hour causes error here
5. You want to schedule a Laravel command to run every weekday at 6:30 PM but only if a certain feature flag is enabled. Which is the best way to implement this in app/Console/Kernel.php?
hard
A. Use if (config('features.enable_task')) { $schedule->command('task:run')->weekdays()->at('18:30'); }
B. Schedule the command daily at 18:30 without condition
C. Use cron expression '30 18 * * 0-6' to run every day
D. Add the condition inside the command handle method instead of scheduler
Solution
Step 1: Understand conditional scheduling
Laravel scheduler allows conditional scheduling by wrapping schedule calls in if statements.
Step 2: Use weekdays() and at() methods
weekdays() limits to Monday-Friday, at('18:30') sets time to 6:30 PM.
Step 3: Apply feature flag condition
Check config('features.enable_task') before scheduling to enable/disable task.
Final Answer:
Use if (config('features.enable_task')) { $schedule->command('task:run')->weekdays()->at('18:30'); } -> Option A
Quick Check:
Conditional scheduling with if + weekdays() + at() [OK]
Hint: Wrap schedule call in if to conditionally enable task [OK]
Common Mistakes:
Scheduling unconditionally ignoring feature flag
Using wrong cron for weekdays
Putting condition inside command instead of scheduler