【发布时间】:2015-01-08 17:35:34
【问题描述】:
我正在为我的包创建一个命令。
我的构造函数是:
public function __construct(\Artisan $artisan)
{
parent::__construct();
$this->artisan = $artisan;
}
受保护的$artisan 属性当然存在。
在我的服务提供者register()方法中,我尝试了几种注册命令的方法。
第一:
$this->app['custom.command'] = $this->app->share(function ($app)
{
return new CustomCommand(new \Artisan);
});
$this->commands('custom.command');
第二:
$this->app['custom.command'] = $this->app->share(function ($app)
{
return $app->make('CustomCommand');
});
$this->commands('custom.command');
通常,它应该可以工作。但是当我运行命令时,我总是在我的 fire() 方法中运行 $this->artisan->call('migrate') 时收到 Call to undefined method Illuminate\Support\Facades\Artisan::call() 错误消息。
但是,当我写 \Artisan::call('migrate') 而不是 $this->artisan->call('migrate') 时,一切正常。
有人知道我做错了什么吗?
提前致谢。
【问题讨论】:
标签: laravel ioc-container laravel-artisan