2016-07-04 128 views
0

作爲我的Laravel 5.2應用程序的一部分,我想爲工匠定義自定義命令,但我的命令未出現在artisan list中。Laravel5控制檯未註冊

1)。我創建了命令骨架:artisan make:console --command=process:emails

2)。我添加了一個比特的測試代碼到新的類的方法handle()

<?php 

namespace App\Console\Commands; 

use App\CommunicationsQueue; 
use Illuminate\Console\Command; 

class ProcessEmailQueueCommand extends Command 
{ 
    /** 
    * The name and signature of the console command. 
    * 
    * @var string 
    */ 
    protected $signature = 'process:email'; 

    /** 
    * The console command description. 
    * 
    * @var string 
    */ 
    protected $description = 'Send all currently pending emails in the queue'; 

    /** 
    * Create a new command instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     parent::__construct(); 
    } 

    /** 
    * Execute the console command. 
    * 
    * @return mixed 
    */ 
    public function handle() 
    { 
     CommunicationsQueue::where('status', 'PENDING')->update(['status'=>'TEST']); 

     $this->info('The mails queue was successfully processed.'); 
    } 
} 

3)。然後,我在app/Console/Kernel.php註冊了命令:

protected $commands = [ 
    'App\Console\Commands\ProcessEmailQueueCommand', 
]; 

我在這裏錯過了什麼?我確信這是一件非常簡單的事情,但我沒有看到它。

+0

就一目瞭然......它看起來像你的沒有正確註冊該命令。 App \ Commands丟失,您沒有輸入完整的命名空間。 – jhmilan

回答

0
app/Console/Kernel.php

嘗試用下面的代碼

protected $commands = [ 
    'App\Console\Commands\ProcessEmailQueueCommand', 
]; 
0

在Kernel.php,嘗試包括全名,這應該是:

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