2015-11-04 105 views
0

我想在Laravel 5建立一个新的自定义命令,像这样:在laravel 5中没有注册命令?

php artisan make:console Tenant --command=tenant:do 

而且它在应用程序\控制台\创建的类命令,如下所示:

<?php 

namespace App\Console\Commands; 

use Illuminate\Console\Command; 

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

    /** 
    * The console command description. 
    * 
    * @var string 
    */ 
    protected $description = 'Run commands for all tenants.'; 

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

    /** 
    * Execute the console command. 
    * 
    * @return mixed 
    */ 
    public function handle() 
    { 
     echo 'Hello World!'; 
    } 
} 

但现在当我尝试

[InvalidArgumentException]有 在“租客”没有定义的命令名称空间:与php artisan tenant:do运行此命令,它与一个错误说返回。

我不知道我在做什么错?

回答

10

你加你的命令app/Console/Kernel.php,如这里的文档概述:http://laravel.com/docs/5.1/artisan#registering-commands

protected $commands = [ 
    'App\Console\Commands\Tenant' 
]; 
+0

愚蠢的错误。 * facepalm *谢谢你帮助我。 :) – Rohan

+0

np,很高兴我能协助。如果你不介意,请接受答案:) –

+1

是的,我当时做不到。它告诉我等一会儿。 :) – Rohan