如何使用 Laravel 任务调度将参数传递给命令

Ale*_*ang 3 laravel laravel-scheduler laravel-artisan

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

protected $signature = 'pull:users {startTime} {endTime} {minutes=10} {--flag} {--star=}';
Run Code Online (Sandbox Code Playgroud)

那么,如何将参数传递给它App\Console\Kernel.php

Ale*_*ang 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();
Run Code Online (Sandbox Code Playgroud)

门面也应该没问题Artisan::call