You can do it exactly the same as in Laravel 4:
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
*.env
个文件只是用来放置不应该放入VCS的敏感数据.拉维尔4号也是如此
but is seems that in last days default detectEnvironment was changed to:
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'production';
});
so you can use either setting variable from PC name or from ENV file.
如果在主环境文件(默认为.env
文件)中使用基于环境的环境检测,则需要添加:
APP_ENV=local
Of course local
here is local environment, you can change it into production
or dev
目前,我看到的最重要的问题是,在进行生产时,您需要记住将这.env
个文件内容从APP_ENV=local
更改为APP_ENV=production
,所以在我看来,更好的方法是基于PC名称的旧的默认方法.
现在是ENV文件.如果您使用基于ENV的环境检测,则应仅将以下内容放入您的ENV文件中:
APP_ENV=local
Now you can create separate ENV files for your different environments for example:
.local.env :
MY_DB=testdb
.production.env:
MY_DB=productiondb
现在在bootstrap.environment.php
个文件中,你可以修改:
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::load(__DIR__.'/../');
}
进入:
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::load(__DIR__.'/../');
if (getenv('APP_ENV') && file_exists(__DIR__.'/../.' .getenv('APP_ENV') .'.env')) {
Dotenv::load(__DIR__ . '/../', '.' . getenv('APP_ENV') . '.env');
}
}
从主环境文件加载基于APP_ENV
的额外环境文件.
Now you will be able to use it in your other configuration file as always: $_ENV['MY_DB']