我正在尝试在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]有 没有在“租户”命名空间中定义的命令。
我不确定我做错了什么?
答案 0 :(得分:10)
您是否已将命令添加到app/Console/Kernel.php
,如此处的文档中所述:http://laravel.com/docs/5.1/artisan#registering-commands
protected $commands = [
'App\Console\Commands\Tenant'
];