Printing env variables in View Hi,
I want to print env variables in my view since I want to debug some issues. Here's what I am trying.
<p> Mail Driver: {{ env('MAIL_DRIVER') }}</p>
<br>
<p> Mail Domain: {{ env('MAILGUN_DOMAIN') }}</p>
<br>
<p> Mail Secret: {{ env('MAILGUN_SECRET') }}</p>
<br>
<p> DB Host: {{ env('DB_HOST') }}</p>
These however are printing blank values in my local environment. On my server it is showing actual values.
Is there something wrong in the way I am printing. Also not sure why I can see values printed on my server but not on my local.
Working fine for me on my local project!
I think you need to clear your view. Laravel is caching your view by default. You can clear your view by running this command
php artisan view:clear
If you then refresh you should see your variables ;)
@bobbybouwmann
So I am using Homestead to run an environment in my local. On Homestead I tried view:clear
I even tried php artisan cache:clear
I tried vagrant reload --provision but it is still showing all blanks
However, it is still showing all blanks. Any suggestions on what else can I try?
I am getting blanks as well
change .env file ie add APP_PHONE="(888) 555-1212"
run php artisan config:cache from command line
from view attempt to put env('APP_PHONE', 'Did not work') => Did not work
what am i missing?
@jbradfield check the big orange warning in the docs for config:cache
If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.
https://laravel.com/docs/5.5/configuration#configuration-caching
So create a new config file (or add to an existing one), use env() in that to set the values from .env, and then use config('filename.keyname') to retrieve it.
.env
APP_PHONE="(888) 555-1212"
config/test.php
return [
'APP_PHONE' => env('APP_PHONE', 'some default value'),
];
view:
{{ config('test.APP_PHONE') }}
Please sign in or create an account to participate in this conversation.