Search code examples
phplaravellaravel-5config

Get environment value in controller


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?


Solution

  • Try it with:

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