简体   繁体   English

Laravel 5获取APP_DEBUG环境变量

[英]Laravel 5 get APP_DEBUG environment variable

On Laravel 5, on a blade template I want to @yield a part of code only if the environment variable APP_DEBUG is set to true. 在Laravel 5上,在刀片模板上,仅当环境变量APP_DEBUG设置为true时,我才想@yield部分代码。 The code on the blade template is: 刀片模板上的代码是:

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

However no matter if I set APP_DEBUG=false on my .env the line env('APP_DEBUG') will always retrieve 1 while all other environment variables will retrieve its correct value. 但是,无论我是否在APP_DEBUG=false上设置APP_DEBUG=falseenv('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

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. 好的,我解决了,我简直不敢相信它是如此简单...调用时, env()函数无法从.env文件中获取值。 Apparently the .env variables are stored somewhere so it is needed to close and start again the server with php artisan serve . 显然.env变量存储在某个位置,因此需要关闭它并重新启动具有php artisan serve的服务器。

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

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