Get environment value in controller

nielsv picture nielsv · Dec 14, 2015 · Viewed 135.6k times · Source

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 without any result:

$hostname = config('IMAP_HOSTNAME_TEST');

The $hostname variable is equal to null. How can I use these configuration variables in my controller?

Answer

Chetan Ameta picture Chetan Ameta · Dec 14, 2015

Try it with:

<?php $hostname = env("IMAP_HOSTNAME_TEST", "somedefaultvalue"); ?>