如何使用Laravel Task Scheduling将参数传递给命令

时间:2019-02-10 04:45:20

标签: laravel artisan laravel-scheduler

作为官方文档,它并没有太多提及。 App\Console\Commands\PullUsersCommand.php的签名如下:

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

因此,如何在App\Console\Kernel.php中传递参数给它

1 个答案:

答案 0 :(得分:0)

您可以像这样在App \ Console \ Kernel.php中调用它:

$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();

Artisan::call外观也应该没问题。