我开发了一个 laravel 5 软件包,现在我想在 laravel 上使用:接口 Gate。
为了使用接口,我应该这样做:
public function boot(GateContract $gate)
{
...code...
$gate->define($permission->name)
...Codes...
}
但我想知道是否有另一种方法使用 GateContract $gate而不使用函数参数或使用类扩展。
我的意思是,我可以这样使用吗:
$gate = new Gate;
或其他任何东西,
尝试类似的东西
$gate = $this->app->make('Gate');
这里有关于Laravel服务容器的更多信息,它实例化了这里的对象 https://laravel.com/docs/5.2/container