2014-09-01 104 views
1

所以我尝试添加一个命令与工匠:“找不到命令”

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

在我的文件中开始/ artisan.php我加

Artisan::add(new MailSendCommand); 

,但是当我输入 'PHP的工匠命令:发送邮件' 它说:

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

这只是工作我的家用电脑(XAMPP)上,但不是我的活的服务器(PHP 5.5.15(CGI-FCGI))

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

回答

1

看起来好像问题与您的设置有关。您正在使用PHP CGI而不是CLI来运行不起作用的命令。

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

1

转到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作为一个有效的工匠命令。检查它是执行中的可用命令之一:

php artisan list