Question: In laravel 4 we had:

```
$env = $app->detectEnvironment(array(
    'local' => array('homestead')
));

```

by default.

But in laravel 5 it's changed to:

```
$env = $app->detectEnvironment(function()
{
    return getenv('APP_ENV') ?: 'production';
});

```

Also, they have excluded **.env.\*** line in .gitignore, now it has:

```
.env

```

And added file .env.example:

```
APP_ENV=local
APP_KEY=SomeRandomString
DB_USERNAME=homestead
DB_PASSWORD=homestead

```

So, if i have more than 2 environments, do i have to set all of them in a single .env file now? E.g.:

```
APP_ENV=local
DB_PASSWORD=123

APP_ENV=alpha
DB_PASSWORD=456

```

If i would have no .env file, how laravel will know what environment i am using?

Answer: 
For those who just upgraded to 5.2: 

You cannot longer use the static `Dotenv::load()` method. Use the following instead:

```
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../', '.' . getenv('APP_ENV') . '.env'); // Laravel 5.2
$dotenv->load();

```

in `bootstrap/app.php`.

//edit
Soo.. after digging into this for the past hour I might as well add some additional info here:

* Laravel uses .env files for configuration
* By default, the file ".env" in the root directory of the application is loaded
* You can access the values within those .env files via the `env()` helper function or directly via PHP's native `getenv()` function. Although you should only do so to fill your config files (see `/config/*.php`), because [those can be cached](https://laravel.com/docs/5.2/configuration#configuration-caching).
* the .env files are loaded in the [DetectEnvironment](https://github.com/laravel/framework/blob/v5.2.10/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php) class. I found this helpful while debugging to set breakpoints. Please take note of the line `(new Dotenv($app->environmentPath(), $app->environmentFile()))->load();`: Since it uses [`load()`](https://github.com/vlucas/phpdotenv/blob/master/src/Dotenv.php#L41) **any environment value that has already been set will not be overwritten!** (You would have to use `overload()` to do so - this drove me *nuts* because homestead sets the `APP_ENV` variable to `local` in the php-fpm config `/etc/php/7.0/fpm/php-fpm.conf` and you cannot change it via .env file)
* when writing unit tests, you usually inherit from [`TestCase`](https://github.com/laravel/framework/blob/v5.2.10/src/Illuminate/Foundation/Testing/TestCase.php), which sets the `APP_ENV` variable to testing (via [`refreshApplication()`](https://github.com/laravel/framework/blob/v5.2.10/src/Illuminate/Foundation/Testing/TestCase.php#L76) -- using `putenv()` to override the default `local` value)
I just wanted to contribute my solution for Laravel 5.1, which is slightly simpler IMHO. In bootstrap/app.php, I have (just after where the Application is instantiated):

```
$app->beforeBootstrapping(\Illuminate\Foundation\Bootstrap\DetectEnvironment::class, function() use ($app) {
    $suffix = (env('APP_ENV')) 
        ? '.'.env('APP_ENV') 
        : '';
    $app->loadEnvironmentFrom('.env'.$suffix);
});

```

There's no need for any checking or error handling. Laravel will default to "production" if the file is not found.

That is all.