命令未定义异常 [英] Command is not defined exception
问题描述
我与工匠创建了一条命令
I created a command with Artisan
$ php artisan command:make NeighborhoodCommand
这创建了文件app/commands/NeighborhoodCommand.php
代码段.我修改了name
值并填写了fire()
函数
Snippet of the code. I modified the name
value and filled in the fire()
function
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class NeighborhoodCommand extends Command {
protected $name = 'neighborhood';
public function fire()
{
// my code
}
}
但是当我尝试使用以下命令运行时
But then when I try to run the command with
$ php artisan neighborhood
我收到此错误:
[InvalidArgumentException]
Command "neighborhood" is not defined.
推荐答案
Laravel 5.5 +
https://laravel.com/docs/5.5/artisan#registering-commands
如果愿意,您可以继续手动注册命令.但是L5.5为您提供了延迟加载它们的选项.如果您要从旧版本升级,请将此方法添加到内核:
If you'd like, you can continue manually registering your commands. But L5.5 gives you the option to lazy load them. If you are upgrading from an older version add this method to your Kernel:
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__ . '/Commands');
require base_path('routes/console.php');
}
Laravel 5
http://laravel.com/docs/5.4/artisan#registering-commands
编辑您的app/Console/Kernel.php
文件并将命令添加到$commands
数组:
Edit your app/Console/Kernel.php
file and add your command to the $commands
array:
protected $commands = [
Commands\NeighborhoodCommand::class,
];
Laravel 4
http://laravel.com/docs/4.2/commands#registering-commands
将此行添加到app/start/artisan.php
:
Artisan::add(new NeighborhoodCommand);
这篇关于命令未定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!