Get environment value in controller

前端 未结 10 1687
既然无缘
既然无缘 2020-12-25 10:43

In my .env file I have the following:

IMAP_HOSTNAME_TEST=imap.gmail.com
IMAP_USERNAME_TEST=myemail@gmail.com
IMAP_PASSWORD_TEST=mypw

Now I

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 11:05

    It's a better idea to put your configuration variables in a configuration file.

    In your case, I would suggest putting your variables in config/mail.php like:

    'imap_hostname' => env('IMAP_HOSTNAME_TEST', 'imap.gmail.com')
    

    And refer to them by

    config('mail.imap_hostname')
    

    It first tries to get the configuration variable value in the .env file and if it couldn't find the variable value in the .env file, it will get the variable value from file config/mail.php.

提交回复
热议问题