简体   繁体   English

缓存外观在Laravel 5中不起作用

[英]Cache facade not working in Laravel 5

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. 但是,当我尝试在config/config.php文件中调用Cache Facade时,出现错误。 Details are given below. 细节在下面给出。

I have following code located in app/config/custom.php : 我在app/config/custom.php有以下代码:

<?php 
// app/config/custom.php

use Illuminate\Support\Facades\Cache;

return [
   'foo' => Cache::get('foo');
];

Which spits out a following error: 这会产生以下错误:

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 致命错误:在第216行上的D:\\ www \\ project \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Support \\ Facades \\ Facade.php中的非对象上调用成员函数get()

How to fix this? 如何解决这个问题?

As discussed in the comments, config files are not meant to store dynamic application values, if it's dynamic (ie 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. 您可以使用服务提供商在整个应用程序中使全局内容可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM