Laravel 4 used a function that checked the servers hostname to determine the environment. Laravel 5 simplifies environment detection by having a .env file present in your project root.
.env.example is ignored by Laravel’s detection. You can fill it with the keys your application expects to act an an example for your own file.
.env is for the current environment
Add .env to your .gitignore file. It’s got to stay out of your repo so you don’t overwrite it each time you pull.
Copy/Rename .env.example to .env for each environment.
set the APP_ENV value within your .env file to tell Laravel where it’s running.
APP_ENV=local APP_DEBUG=true APP_KEY=123abc...
$app->environment(); //get the current environment if($app->environment('local', 'staging')) { } //test if local or staging env
You can retrieve your .env config values with the env() function.
$cfgValue = env('MY_SWEETAS_VARIABLE');
One thought on “Laravel 5 Environment Config”