我创建了一个名为AttachUsers的命令。当我运行命令时,我得到了
Argument 1 passed to AttachPhones::__construct() must be an instance of Acme\\Repositories\\Organizations\\OrganizationRepositoryInterface, none given, called in \/Users\/jonson\/sites\/acme\/app\/start\/artisan.php on line 5 and defined","file":"\/Users\/jonson\/sites\/acme\/app\/commands\/AttachPhones.php","line":30}}
我已将我的界面绑定在存储库服务提供程序文件中,并且它当前正在我的控制器中进行操作。我的命令文件如下
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use \Acme\Repositories\Organizations\OrganizationRepositoryInterface;
class AttachUsers extends Command {
protected $organizations;
/**
* The console command name.
*
* @var string
*/
protected $name = 'acme:attach_users';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cron command to attach users from import to organizations';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(OrganizationRepositoryInterface $organizations)
{
$this->organizations = $organizations;
parent::__construct();
}
答案 0 :(得分:1)
你可能正在呼叫Artisan::add(new MyCommand)
。每次使用“new”关键字时,IoC容器都会被完全绕过,自动依赖注入将不工作。相反,请使用Artisan::add(App::make('MyCommand'))
或速记Artisan::resolve('MyCommand')
。