【发布时间】:2015-07-03 13:53:29
【问题描述】:
我正在使用 laravel 5 处理我的一个项目。在实施过程中,我遇到了一个与命令和处理程序相关的问题的结构。
我使用artisan命令生成命令
php artisan make:command TestCommand --handler
我在 app/commands 文件夹“TestCommand.php”中生成了命令
<?php
namespace App\Commands;
use App\Commands\Command;
class TestCommand extends Command
{
public $id;
public $name;
public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}
}
我的 TestCommandHandler.php 也是这样的
<?php
namespace App\Handlers\Commands;
use App\Commands\TestCommand;
use Illuminate\Queue\InteractsWithQueue;
class TestCommandHandler
{
/**
* Create the command handler.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the command.
*
* @param TestCommand $command
* @return void
*/
public function handle(TestCommand $command)
{
dd($command);
}
}
每当从控制器发送此命令时,它都会显示以下问题
InvalidArgumentException in Dispatcher.php line 335:
No handler registered for command [App\Commands\TestCommand]
请有人帮我解决这个问题。谢谢
【问题讨论】: