Laravel 5 获取 APP_DEBUG 环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29929615/
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 11:27:57  来源:igfitidea点击:

Laravel 5 get APP_DEBUG environment variable

phplaravellaravel-5

提问by adelriosantiago

On Laravel 5, on a blade template I want to @yielda part of code only if the environment variable APP_DEBUG is set to true. The code on the blade template is:

在 Laravel 5 上,在刀片模板上@yield,仅当环境变量 APP_DEBUG 设置为 true 时,我才想要一部分代码。刀片模板上的代码是:

@if(env('APP_DEBUG') == 1)
    @yield('debugcontrols')
@endif

However no matter if I set APP_DEBUG=falseon my .env the line env('APP_DEBUG')will always retrieve 1 while all other environment variables will retrieve its correct value.

但是,无论我是否APP_DEBUG=false在 .env 上设置,该行将env('APP_DEBUG')始终检索 1,而所有其他环境变量将检索其正确值。

How do I get the APP_DEBUG environment variable?

如何获取 APP_DEBUG 环境变量?

Note that all other environment variables print correctly, for example with,

请注意,所有其他环境变量都正确打印,例如,

APP_DEBUG=false
DB_HOST=localhost

The code,

编码,

{{ env('DB_HOST') }}
{{ env('APP_DEBUG') }}
{{ Config::get('app.debug') }}

will render,

将呈现,

localhost 1 1

回答by adelriosantiago

Ok, I solved it, I can't believe it was so simple... The function env()does not gets the values from the .env file when called. Apparently the .env variables are stored somewhere so it is needed to close and start again the server with php artisan serve.

好的,我解决了它,我不敢相信它是如此简单......该函数env()在调用时不会从 .env 文件中获取值。显然 .env 变量存储在某处,因此需要关闭并使用 .env 重新启动服务器php artisan serve