在laravel 5中没有注册命令?

时间:2015-11-04 05:29:23

标签: php laravel laravel-5

我正在尝试在Laravel 5中构建一个新的自定义命令,如下所示:

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

它在App \ Console \ Commands中创建了类,如下所示:

<?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!';
    }
}

但是现在当我尝试使用php artisan tenant:do运行此命令时,它会返回错误信息:

  

[InvalidArgumentException]有   没有在“租户”命名空间中定义的命令。

我不确定我做错了什么?

1 个答案:

答案 0 :(得分:10)

您是否已将命令添加到app/Console/Kernel.php,如此处的文档中所述:http://laravel.com/docs/5.1/artisan#registering-commands

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