如何使用 Laravel 任务计划将参数传递给命令

How to pass parameters to command with Laravel Task Scheduling

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

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

那么,如何在App\Console\Kernel.php

中给它传递参数

您可以在 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 门面应该没问题。