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: 
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.
The fact that you can't have more than one `.env` file by default *and* that it's excluded in .gitignore is intentional and is the intended way to manage environments. The `.env` file should not be in version control and should be configured per environment. `.env` sets your environment and all environment variables.

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

No. You would have a `.env` file in each place that you have your application installed. The difference is in what is inside that file.

Additionally, because the `.env` file is simply a key-value store, any subsequent declarations would overwrite previous ones. In your example, Laravel would never see your "local" settings.

It seems odd at first, but this new default system is actually generally easier and less prone to the issues the "4.2 way" had/has, as there's no place for logic errors.

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

It wouldn't run at all. In the `.env` file is also an `APP_KEY` declaration, which Laravel will not run without. Without a `.env` file, you would get a 500 server error.