【发布时间】:2015-11-03 17:16:24
【问题描述】:
我创建了一个名为 sendUnreadNotifications 的工匠命令,如果用户有未读通知,它会触发系统向用户发送电子邮件。最终这将通过 cron 作业运行,用户可以每小时更新或每天更新。
出于这个原因,我想用我的命令发送一个参数,像这样,
php artisan command:name sendUnreadNotifications H --env=local
但是运行这个,我得到以下错误,
[运行时异常]
参数太多。
我的代码,看起来像这样,
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class sendUnreadNotifications extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$request = Request::create('api/notifications/send/unread', 'GET', array($this->getArguments()));
Route::dispatch($request)->getContent();
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('frequency', InputArgument::OPTIONAL, 'How often should the email be sent', 'H'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
我不明白为什么我会得到太多参数异常?
【问题讨论】:
标签: php laravel laravel-artisan