I make a command that is called through the controller. When I make a simple example of a command and controller like this, it works:
$command = new TestCommand();
$this->dispatch($command);
public $name;
public function __construct()
{
$this->name = 'hi';
}
public function handle(TestCommand $command)
{
dd($command->name);
}
When I call the command through the controller, I get a "hello", which is correct. But when I try to pass something through the constructor, I get an exception to resolve the binding:
$command = new TestCommand('hi');
$this->dispatch($command);
public $name;
public function __construct($name)
{
$this->name = $name;
}
public function handle(TestCommand $command)
{
dd($command->name);
}
Why is this? What I did is similar to what I found in the Laravel docs example, but I get this exception:
BindingResolutionException in line Container.php 872: Resolution of an unsolvable dependency [Parameter # 0 [$ name]] in the class App \ Commands \ TestCommand
source
share