缓存外观在Laravel 5中不起作用 [英] Cache facade not working in Laravel 5

查看:64
本文介绍了缓存外观在Laravel 5中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望某些设置可由用户管理.因此,我将它们存储在数据库中,然后检索并缓存它们.但是,当我尝试在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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆