Task Scheduling: Automating Recurring Jobs
Run recurring jobs like cleanup and reports using Laravel’s scheduler instead of manual cron scripts.
Laravel’s scheduler allows you to define cron jobs in code. ## Define schedule ```php protected function schedule(Schedule $schedule) { $schedule->command('reports:daily')->dailyAt('01:00'); $schedule->call(fn () => Log::info('heartbeat'))->everyMinute(); } ``` ## System cron ```bash * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 ``` ## Flow ```mermaid flowchart LR A[Cron] --> B[schedule:run] B --> C[Due Tasks] C --> D[Execute] ``` Scheduling centralizes automation in one place. In the next tutorial, we will cache data to improve performance.