未列出 laravel 自定义命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28371744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:51:20  来源:igfitidea点击:

laravel custom command not listed

phplaravelartisan

提问by maximus 69

I have created a custom command called confirmUserCommandwith the filename matching the class name (same case). The $name is set to confirmuser.

我创建了一个自定义命令confirmUserCommand,其文件名与类名匹配(大小写相同)。$name 设置为confirmuser.

Running the command php artisan listdisplays the new command on my local, but not on the server (which is running linux). I did perform a composer dump-autoload and update the relevant composer files to no avail.

运行该命令php artisan list会在我的本地显示新命令,但不会在服务器(运行 linux)上显示。我确实执行了 composer dump-autoload 并更新了相关的 composer 文件,但无济于事。

Any suggestions please?

请问有什么建议吗?

采纳答案by maximus 69

Just tore my hair out and found out the issue..

刚把我的头发扯掉,发现了问题。。

In order to list the artisan commands including the custom ones, you have to invoke the systems PHP CLI Intepreter specifically PHP call.

为了列出包括自定义命令在内的 artisan 命令,您必须调用系统 PHP CLI Intepreter,特别是 PHP 调用。

php artisan list: would list all the commands as expected but not the custom commands you created

php artisan list: 会按预期列出所有命令,但不会列出您创建的自定义命令

php-cli artisan list: This would list the all commands including the custom commands created

php-cli artisan list:这将列出所有命令,包括创建的自定义命令

Hope this helps someone and save their hair :)

希望这可以帮助某人并挽救他们的头发:)

回答by A H Bensiali

Laravel 5.2 ~ 5.5:

Laravel 5.2 ~ 5.5:

Create your command & edit

创建您的命令并编辑

   protected $signature = 'order:check'; //or whatever you want your command to be

You will have to find where the commands are created & edit the app\Console\kernel.phpfile.

您必须找到创建命令的位置并编辑app\Console\kernel.php文件。

in this file under

在这个文件下

protected $commands = [
    \App\Console\Commands\OrderCheck::class,
]

run again

再次运行

 php artisan list 

It should be listed there :)

它应该在那里列出:)

回答by YDF

From laravel version 5.6 onwards you need not make the entry of your custom command in kernel.php.

从 laravel 5.6 版开始,您无需在 kernel.php 中输入自定义命令。

回答by Luis Mata B.

In order to make it appear in the php artisan list you need to add it to the App/http/Kernel.php file specifically in the commands array:

为了使它出现在 php artisan 列表中,您需要将它添加到 App/http/Kernel.php 文件中的命令数组中:

 protected $commands = [
   'App\Console\CreateSlugsCommand',....
];

After you do that you can run in your console php artisan listand you you will see the custom command.

完成后,您可以在控制台中运行,您php artisan list将看到自定义命令。