Laravel 5.2 无法设置配置值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35595471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:17:37  来源:igfitidea点击:

Laravel 5.2 can not set config value

laravelconfig

提问by Brotzka

I have the problem that I can not set my configuration values through the config() function.

我的问题是我无法通过 config() 函数设置我的配置值。

I have my own config file (cms.php in config/). The value I want to change is 'index'.

我有我自己的配置文件(在 config/ 中的 cms.php)。我要更改的值是“索引”。

In my ConfigController I try to set the value with this:

在我的 ConfigController 我尝试用这个设置值:

config(['cms.index' => $page_id]);

Any solutions? Do I have to import a special class?

任何解决方案?我必须导入一个特殊的类吗?

回答by Muhammet

config(['cms.index' => $page_id]);will set the value for runtime only. It won't save it to the config file.

config(['cms.index' => $page_id]);将仅为运行时设置值。它不会将其保存到配置文件中。

If you want persistent configurations take a look at Update Config on Runtime Persistently

如果您想要持久配置,请查看持续运行时更新配置

回答by oseintow

Change it to \Config::set('cms.index', $page_id);

将其更改为 \Config::set('cms.index', $page_id);