【发布时间】:2019-05-11 01:23:50
【问题描述】:
Laravel 像这样将 pathis 绑定到容器中
$this->instance('path.lang', $this->langPath());
在 /vendor/laravel/framework/src/Illuminate/Foundation/Application.php 中的 bindPathsInContainer() 中,我想将此路径从我的服务提供者中更改为其他路径。
我知道容器实例可以通过 $this->app 从服务提供者中访问,所以我想我可以这样做
$this->app->instance('path.lang', 'my/path');
然而,这会返回“类实例不存在”。谁能解释这里发生了什么? 另外,为什么要引用容器的任何属性,如
$this->app->someProperty
导致这个错误?有没有办法从服务提供商内部编辑 someProperty?注意:我知道这可以通过扩展 \Illuminate\Foundation\Application 来完成,正如 here 所解释的那样,但我想这样做,而不必触及 Laravel 的默认文件。
【问题讨论】: