You can not access the environment variable like this.
Inside the .env
file you write
IMAP_HOSTNAME_TEST=imap.gmail.com // I am okay with this
Next, inside the config
folder there is a file, mail.php. You may use this file to code. As you are working with mail functionality. You might use another file as well.
return [
//..... other declarations
'imap_hostname_test' => env('IMAP_HOSTNAME_TEST'),
// You are hiding the value inside the configuration as well
];
You can call the variable from a controller using 'config(
.
Whatever file you are using inside config folder. You need to use that file name (without extension) + '.' + 'variable name' + ')'
. In the current case you can call the variable as follows.
$hostname = config('mail.imap_hostname_test');
Since you declare the variable inside mail.php and the variable name is imap_hostname_test
, you need to call it like this. If you declare this variable inside app.php
then you should call
$hostname = config('app.imap_hostname_test');