Get environment value in controller
Step 1.) Add your variable to your
.env
file, ie.EXAMPLE_URL="http://google.com"
Step 2.) Create a new file inside of the
config
folder, any name, ie.config/example.php
Step 3.) Inside of this new file, I add an array being returned, containing that env variable.
<?php
return [
'url' => env('EXAMPLE_URL')
];
Step 4.) Because I named it "example" my configuration 'namespace' is now an example. So now, in my controller I can access this variable with:
$url = \config('example.url');
Examplepublic static function mail($param)
{
//$_ENV['yourkeyhere'];
$mailgunsecret = env('MAILGUN_SECRET');
$mailguurl = env('MAILGUN_DOMAIN');
}
$data = array("MAIL_DRIVER" => env('MAIL_DRIVER'),"MAIL_HOST" => env('MAIL_HOST'),"MAIL_PORT" => env('MAIL_PORT'),"MAIL_USERNAME" => env('MAIL_USERNAME'),"MAIL_PASSWORD" => env('MAIL_PASSWORD'),"MAIL_ENCRYPTION" => env('MAIL_ENCRYPTION'));$response = json_encode($data);return response()->json(['status' => "ok",'data' => $response ], 200);