laravel 工匠:“找不到命令”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25607800/
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:01:42  来源:igfitidea点击:

Artisan: "Command not found"

laravellaravel-4

提问by jascha

So I try to add a Command with

所以我尝试添加一个命令

php artisan command:make MailSendCommand

The file MailSendCommand.php is created. I edited it to this:

创建文件 MailSendCommand.php。我把它编辑成这样:

class MailSendCommand extends Command {

    protected $name = 'command:send-mail';

    protected $description = 'Send mails to the users.';


    public function __construct()
    {
        parent::__construct();
    }


    public function fire()
    {
        $this->info('Befehl wird ausgeführt' );
    }
...

In my file start/artisan.php I added

在我的文件 start/artisan.php 中,我添加了

Artisan::add(new MailSendCommand);

but when I enter 'php artisan command:send-mail' it says:

但是当我输入“php artisan command:send-mail”时,它说:

Command "command:send-mail" is not defined.

It just worked on my Home PC (XAMPP) but not on my live server (PHP 5.5.15 (cgi-fcgi))

它只适用于我的家用电脑 (XAMPP),但不适用于我的实时服务器 (PHP 5.5.15 (cgi-fcgi))

'php artisan clear:cache' and 'php artisan dump-autoload' did not help.

'php artisan clear:cache' 和 'php artisan dump-autoload' 没有帮助。

采纳答案by Hassan

It looks as though the problem is related to your setup. You're using PHP CGI instead of CLI to run your commands which will not work.

问题似乎与您的设置有关。您正在使用 PHP CGI 而不是 CLI 来运行无法运行的命令。

Ensure that the code is there on your live environment and run your commands on CLI, as these are command line scripts.

确保代码在您的实时环境中并在 CLI 上运行您的命令,因为这些是命令行脚本。

回答by EliuX

Go to app/Console/Kernel.phpand add the class to the commandsvariable. It would look something like:

转到app/Console/Kernel.php并将类添加到commands变量中。它看起来像:

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\MyCustomCommand::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
    }
}

Here i added MyCustomCommandas a valid artisan command. Check it is among available commands executing:

在这里我添加MyCustomCommand了一个有效的工匠命令。检查它是否在执行的可用命令中:

php artisan list