I created a command with Artisan

$ php artisan command:make NeighborhoodCommand

This created the file app/commands/NeighborhoodCommand.php

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

I get this error:

[InvalidArgumentException]
Command "neighborhood" is not defined.

推荐答案

Laravel 5.5+

https://laravel.com/docs/5.5/artisan#registering-commands

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数组:

protected $commands = [
    Commands\NeighborhoodCommand::class,
];

Laravel 4

http://laravel.com/docs/4.2/commands#registering-commands

将此行添加到app/start/artisan.php:

Artisan::add(new NeighborhoodCommand);

Laravel相关问答推荐

如何更改LIVE上的Filament占位符内容?

Laravel 通过 API 嵌套 url 发布

按回车键时如何防止此功能运行?

Laravel查询多对多关系

如何使用 Laravel 查询生成器在 WHERE 条件周围添加括号

如何在laravel中将数组转换为字符串?

判断 Laravel 中是否存在唯一索引键

Laravel 4:验证前修剪输入的最佳实践

Laravel 5.2 中的正则表达式验证

Laravel Input:all() 忽略禁用的输入

你如何在自定义 Laravel Nova 工具中使用确认对话?

SQLSTATE [42000]:语法错误或访问冲突:1066 Not unique table/alias on relationship

php Laravel-遇到格式不正确的数值(在字符串上)

如何更改 Handlebars.js 的默认分隔符?

Laravel 动作未定义

数组的旧输入?

在 Laravel 应用程序中在哪里指定应用程序版本?

如何在 Laravel 中 Refresh刷新用户对象?

将值插入隐藏输入 Laravel Blade

laravel:如何获取 eloquent 模型的列名?