phpdotenv
What is difference between use env(‘APP_ENV’), config(‘app.env’) or App::environment() to get app environment?
In Short & up-to-date 2022: use env() only in config files use App::environment() for checking the environment (APP_ENV in .env). use config(‘app.var’) for all other env variables, ex: config(‘app.debug’) create own config files for your own ENV variables. Example: In your .env: MY_VALUE=foo example config/myconfig.php return [ ‘myvalue’ => env(‘MY_VALUE’, ‘bar’), // ‘bar’ is default … Read more
Laravel 5 – env() always returns null
env(…) function will not work after you cached the config. (starting from laravel 5.2 till current 5.7) The Laravel documentation says If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application. … Read more