With Laravel, you should avoid environmental variables outside of your configuration files.
In your config files, you can use environmental variables, example in config/app.php:
'env' => env('APP_ENV', 'production'),
Then you can access this using the config helper: config('app.env')
.
This allows you to cache your configuration and still access these values, since env('APP_ENV')
will no longer work once your config is cached.
As docs mention:
"If you execute the config:cache
command during your deployment process, you should be sure that you are only calling the env
function from within your configuration files. Once the configuration has been cached, the .env
file will not be loaded and all calls to the env
function will return null
."