代码之家  ›  专栏  ›  技术社区  ›  Alex Chiang

如何通过Laravel任务调度将参数传递给命令

  •  0
  • Alex Chiang  · 技术社区  · 7 年前

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

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

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

    1 回复  |  直到 7 年前
        1
  •  5
  •   Alex Chiang    7 年前

    你可以在App\Console\Kernel中调用它。比如:

    $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 门面也是。

    推荐文章