我希望某些设置可由用户管理.因此,我将它们存储在数据库中,然后检索并缓存它们.但是,当我尝试在config/config.php文件中调用Cache门面时,出现错误.详细信息如下.
I want some settings to be user-manageable. Because of this, I am storing them in database, retrieving and caching them afterwards. However, when I try to call Cache facade inside the config/config.php file, I get an error. Details are given below.
我在app/config/custom.php中有以下代码:
<?php // app/config/custom.php use Illuminate\Support\Facades\Cache; return [ 'foo' => Cache::get('foo'); ];哪个出现以下错误:
致命错误:在非对象中调用成员函数get() D:\ www \ project \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Facades \ Facade.php 在第216行
Fatal error: Call to a member function get() on a non-object in D:\www\project\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 216
该如何解决?
推荐答案如注释中所述,配置文件并非旨在存储动态应用程序值,如果它是动态的(即用户特定的值),则应以不同的方式处理它们部分应用程序.
As discussed in the comments, config files are not meant to store dynamic application values, if it's dynamic (i.e. User specific values), you should handle them in different parts of the application.
您可以使用服务提供商在整个应用程序中使全局内容可用.
You can make something available globally throughout your application by using Service Providers.
更多推荐
缓存外观在Laravel 5中不起作用
发布评论