简体   繁体   English

配置文件中声明的数组不反映 Laravel 中 config:clear 后的更改

[英]Array declared in config file does not reflect changes after config:clear in Laravel

I have a constants file located in \\config\\constants.php and it's an array of all the constants I am using in my project.我在\\config\\constants.php有一个常量文件,它是我在项目中使用的所有常量的数组。

Sample declaration of the array in the file:文件中数组的示例声明:

return [
'contant_1' => [
    'value_1' => 'a',
    'value_2' => 'b',
    'value_3' => 'c'
],
'constant_2' => [
    'value_1' => 'd',
    'value_2' => 'e',
    'value_3' => 'f'
],
'constant_3' => [
    'value_1' => 'g',
    'value_2' => 'h',
    'value_3' => 'i'
], (...and so on)
];

note, this isn't the real value of the constants注意,这不是常量的真实值

So 'value_3' originally wasn't part of the array, and I included them and updated the array later on.所以 'value_3' 最初不是数组的一部分,我包括它们并稍后更新数组。 I used php artisan config:clear after the updated.我在更新后使用了php artisan config:clear

Now, I can access basically all the values of the constants, including the new 'value_3' index, except for one constant.现在,我基本上可以访问常量的所有值,包括新的'value_3'索引,除了一个常量。 So for example I can get the value of 'constant_1' => 'value_3' as well as 'constant_2' => 'value_3' but for some reason, constant_3 does not have a 'value_3' even though I included it.因此,例如我可以获得'constant_1' => 'value_3'以及'constant_2' => 'value_3'但由于某种原因, constant_3没有'value_3'即使我包含它。

When I try to print it on the console, it's blank.当我尝试在控制台上打印它时,它是空白的。 But for the rest of the constants in the array, they all have that 'value_3' .但是对于数组中的其余常量,它们都具有'value_3' I tried the php artisan config:clear and php artisan config:cache I also tried restarting my local server and still that 'constant_3' doesn't have that 'value_3' .我尝试了php artisan config:clearphp artisan config:cache我也尝试重新启动我的本地服务器,但'constant_3'仍然没有那个'value_3' I can even get the first 2 values of 'constant_3' and it's weird that the 3rd one is just blank.我什至可以得到'constant_3'的前 2 个值,奇怪的是第三个值是空白的。

Please let me know what I'm doing wrong.请让我知道我做错了什么。 I can't seem to find a similar problem anywhere.我似乎在任何地方都找不到类似的问题。 Thanks.谢谢。

Try php artisan cache:clear see if this works.试试php artisan cache:clear看看这是否有效。

Edit: If its still not working try all clear commands and restart server.编辑:如果它仍然无法正常工作,请尝试所有清除命令并重新启动服务器。

    php artisan cache:clear
    php artisan view:clear
    php artisan route:clear
    php artisan config:clear

and restart server.并重启服务器。

Try尝试

php artisan config:cache

For clearing config cache.用于清除配置缓存。

What do you mean by "included them and updated the array later on" ? “包含它们并稍后更新数组”是什么意思? Don't include files manually in lavarel.不要在 lavarel 中手动包含文件。 If you need to update config values in runtime, use Config::set instead.如果您需要在运行时更新配置值,请改用 Config::set。

请尝试php artisan cache:clear

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

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