【问题标题】:How to pass parameters to command with Laravel Task Scheduling如何使用 Laravel 任务调度将参数传递给命令
【发布时间】:2019-07-03 22:27:35
【问题描述】:

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

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

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

【问题讨论】:

    标签: laravel laravel-artisan laravel-scheduler


    【解决方案1】:

    您可以像这样在 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 外观也应该没问题。

    【讨论】:

      猜你喜欢
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      相关资源
      最近更新 更多