gpt4 book ai didi

laravel - 命令未定义异常

转载 作者:行者123 更新时间:2023-12-04 00:14:02 25 4
gpt4 key购买 nike

我用工匠创建了一个命令

$ php artisan command:make NeighborhoodCommand


这创建了文件 app/commands/NeighborhoodCommand.php

代码段。我修改了 name值并填写了 fire()函数

<?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
}
}


但是当我尝试使用以下命令运行命令时

$ php artisan neighborhood


我收到此错误:

[InvalidArgumentException]
Command "neighborhood" is not defined.

最佳答案

Laravel 5.5+

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

如果需要,您可以继续手动注册命令。但是L5.5允许您选择延迟加载它们。如果要从旧版本升级,请将此方法添加到内核中:

/**
* 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 - 命令未定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23462266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com