I need to set admin email in many place. so I created constants.php in config folder.
<?php
return array(
'admin_email' =>'joe@doe.com',
'admin_name' =>'Admin',
);
I was able to access this in my routes.php
dd(Config::get('constants.admin_email'));
However, when I try to access it in mail.php by
'from' => [
'address' => Config::get('constants.admin_email'),
'name' => Config::get('constants.admin_name')
],
I got Class 'Config' not found in mail.php.
Any suggestions? Thanks.
After some testing, I've found you can't use Config
, \Config
or config()
in any files in your config
folder. I believe they are not available to any of these files, but I'm not 100% sure why this is.
Regardless, to solve this issue and still have them available in other parts of your application, use env
or environment variables. In your .env
file, add the following:
ADMIN_EMAIL=joe@doe.com
ADMIN_NAME=Admin
Then, in your mail.php
and anywhere else you want to use them, access them using:
'from' => [
'address' => env('ADMIN_EMAIL'),
'name' => env('ADMIN_NAME')
],
You can actually see them already in use in your mail.php
and other config
files, so it makes sense to use what already works. Hope that helps!
Use
config('constants.admin_email');