如何在Laravel任务调度中传递参数给命令

3

根据官方文档,它并没有详细说明这个问题。 App\Console\Commands\PullUsersCommand.php 的签名如下:

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

因此,如何将参数传递给在App\Console\Kernel.php中的命令呢?
1个回答

6
您可以在 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门面应该也可以。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接