多参数控制台命令上的参数时间不存在

问题描述

我在laravel项目中做了以下命令:

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Covid19CloseTimeOverride extends Command
{

    protected $signature   = 'store:covid19:override {time: Time that goverment closes the restaurants} {ids*: The list of store Ids that close on the provided time} ';
    protected $description = "Overrides store's close times if measures against Covid19 are applied on a specific area";

    public function handle()
    {
        $time      = $this->argument('time');
        $store_ids = $this->argument('store_ids');

        dump($time,$store_ids);
    }
}

然后在控制台中运行以下命令:

  php artisan store:covid19:override 20:00 52 1234 66 77

我收到以下错误:

  Too many arguments,expected arguments "command" "time: Time that goverment closes the restaurants" "store_ids*: The list of store Ids that close on the provided time".  

您知道为什么会收到错误以及如何解决该错误吗?

解决方法

问题是您的签名。

当前签名为:

store:covid19:override {time: Time that goverment closes the restaurants} {ids*: The list of store Ids that close on the provided time}

含义是:

  • time: Time that goverment closes the restaurants
  • ids*: The list of store Ids that close on the provided time

因此,为了便于访问,您应该使用以下argument调用来获取它们:

        $time=$this->argument('time: Time that goverment closes the restaurants');
        $store_ids=$this->argument('ids*: The list of store Ids that close on the provided time');

是的,所以有点像PITA,以便使您之前的代码正常工作:

        $time      = $this->argument('time');
        $store_ids = $this->argument('store_ids')

在参数和space之间放置:,导致此命令签名:

store:covid19:override {time : Time that goverment closes the restaurants} {ids* : The list of store Ids that close on the provided time}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...