问题描述
我在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}