gpt4 book ai didi

laravel - 工匠 : "Command not found"

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

所以我尝试添加一个命令

php artisan command:make MailSendCommand

文件 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' );
}
...

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

Artisan::add(new MailSendCommand);

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

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

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

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

最佳答案

转到 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();
}
}

我在这里添加了 MyCustomCommand 作为有效的 artisan 命令。检查它是否在执行的可用命令中:

php artisan list

关于laravel - 工匠 : "Command not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25607800/

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