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

编程入门 行业动态 更新时间:2024-10-13 18:27:53
本文介绍了缓存外观在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中不起作用

本文发布于:2023-11-26 08:40:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   中不   外观   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!