In my .env file I have the following:
IMAP_HOSTNAME_TEST=imap.gmail.com [email protected] IMAP_PASSWORD_TEST=mypw
Now I would like to use them in my controller. I’ve tried this but with no result:
$hostname = config('IMAP_HOSTNAME_TEST');
The $hostname variable is equal to null. How can I use these config variables in my controller?
try it with
<?php $hostname = env("IMAP_HOSTNAME_TEST", "somedefaultvalue"); ?>
All of the variables listed in
.env file will be loaded into the
$_ENV PHP super-global when your application receives a request.
Checkout laravel configuration page
May be not related, but it might help someone…. in Laravel just dd(config(‘app.env’));
and you’ll see ‘local’ or ‘production’