我正在使用laravel 5.1。在debian bash shell中。我创建了一个名为survey:complete的自定义控制台命令。我已经使用了一段时间了,现在我想为要生成的调查数量添加一个可选参数。
但是,我已经按照文档,但我无法成功添加我的论点。我同样改变了签名:
protected $signature = 'survey:complete {--number=}';
并试图引用这个论点
public function handle() {
for( $i = 0; $i < $this->argument('number'); $i++ ) {
但我得到这个错误:
$> php artisan survey:complete --number=1
[InvalidArgumentException]
The "number" argument does not exist.
我print_r()'参数数组,我得到这个:
$ php artisan survey:complete --number=1
Array(
[command] => survey:complete
)
[InvalidArgumentException]
The "number" argument does not exist.
如何将我的参数添加到我的命令中?
我需要使用option()
,而不是argument()
。
$number = $this->option('number');
为我而工作:
protected $signature = 'mycommand {limit=1000}'
// call: php artisan mycommand 100
我用以下方法检索值:
public function handle() {
// ...
$limit = $this->arguments('limit')['limit']
// ...
}