Skip to content

Schedule tasks from a module

To run a task from the Blog module on a schedule, override configureSchedules() in the module service provider. You need an enabled Blog module and a command to schedule (see Add Artisan commands to a module).

  1. Uncomment configureSchedules() in Modules/Blog/app/Providers/BlogServiceProvider.php and register your scheduled command. The generated provider already imports Illuminate\Console\Scheduling\Schedule.

    Modules/Blog/app/Providers/BlogServiceProvider.php
    protected function configureSchedules(Schedule $schedule): void
    {
    $schedule->command('blog:prune-old')->daily();
    }

    Use protected or public visibility (not private) with the Schedule parameter.

  2. Check the result.

    Terminal window
    php artisan schedule:list
    0 0 * * * php artisan blog:prune-old .......... Next Due: <time>

Pass command arguments as an array:

Modules/Blog/app/Providers/BlogServiceProvider.php
$schedule->command('module:prune', ['Blog'])->daily();

configureSchedules() skips web requests. It runs only when Laravel resolves Schedule (such as during schedule:run or schedule:list), after every service provider has booted. Disabling the module removes its scheduled tasks.