Laravel像这样将pathis绑定到Container中
$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所述,但我是'd like to do this from without having to touch Laravel'的默认文件 .
1 回答
我认为这条道路必须是绝对的:
您也可以在AppServiceProvider中尝试这样做: