Laravel assumes that .env
file should describe environment, and it should not be committed to your repo.
What if I want to keep both .env
f
I'd like to share my two cents on this, for team working on different machines / hosts.
I create a directory env
on app's root, containing:
.master.env
file with the main and shared configuration. .name
file containing only a string with the environment's name for specific machine / purpose (e.g. "server1").server1.env
.Then, in bootstrap/app.php:
/**
* master config
*/
$app->useEnvironmentPath(__DIR__.'/../env');
$app->loadEnvironmentFrom('.master.env');
/**
* config overloading
*/
$app->afterLoadingEnvironment(function() use($app) {
$envFile = trim(file_get_contents($app->environmentPath().'/.name'));
if ($envFile && file_exists($app->environmentPath().'/.' .$envFile .'.env')) {
$dotenv = Dotenv\Dotenv::create($app->environmentPath(), '.'.$envFile.'.env');
$dotenv->overload();
}
});
Now you can selectively override configuration keys for specific machines and if you don't have security issues you can put the env files in VCS , as long as you ignore the `.name' file.
Working in Laravel 5.8.