Search code examples
laravellaravel-artisanlaravel-scheduler

How to pass parameters to command with Laravel Task Scheduling


As the official docs, it doesn't mention about this a lot. App\Console\Commands\PullUsersCommand.php has a signature like:

protected $signature = 'pull:users {startTime} {endTime} {minutes=10} {--flag} {--star=}';

So, how to pass the parameters to it in App\Console\Kernel.php


Solution

  • You could call it in App\Console\Kernel.php like this:

    $schedule->command('pull:users', [
        time(),  // captured with $this->argument('startTime') in command class.
        time(),  // captured with $this->argument('endTime') in command class.
        30,      // captured with $this->argument('minutes') in command class.
        '--flag',// should be without any value, just the option name, and would be captured by $this->option('minutes').
        '--star'=>12, // would be captured by $this->option('star').
    ])->daily();
    

    It should be okay with Artisan::call facade too.