1

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. 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.

How do I get the APP_DEBUG environment variable?

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
2
  • Did you have any other setting to allow Blade to echo an env variable? When I try {{ env('APP_DEBUG') }} I get nothing.. Commented May 27, 2016 at 19:42
  • Same thing for me @greener. But I managed to pull something out in my blade view with. {{ config('app.name') }} will return APP_NAME from my .env file. Of course when ever you make changes to .env file, be sure to run php artisan config:cache to let you application know to clean the config cache. My version of laravel 5.3.30. Commented Feb 1, 2017 at 13:10

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In memory, I would imagine.
0

Maybe you have cached configs? Then you should run one of this commands:

php artisan config:clear

and after this

php artisan config:cache

config:cache

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.