编辑:找出我哪里出错并在最后放置了一个答案
我正在尝试创建一个 Laravel 命令,我可以看到它与 Laravel 3 中的“任务”发生了很大变化。但是我似乎无法让它运行。这些是我采取的步骤:
php artisan 命令:make 导入
退货
命令创建成功
然后创建命令目录中的文件,我稍作修改以返回“Hello World”,如下所示:
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class Import extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:import';
/**
* 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 void
*/
public function fire()
{
return 'Hello World';
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('example', InputArgument::REQUIRED, 'An example argument.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
但是,当我尝试像这样运行命令时:
php工匠导入
我收到以下错误:
[InvalidArgumentException] 命令“导入”未定义。
我已经尝试过使用和不使用大写字母以及将其命名为“ImportCommand”,因为文档将其命令命名为“FooCommand”但没有运气。
非常感激任何的帮助。