dev-master
9999999-devSimple per-environment .env files for Laravel 5.
MIT
The Requires
- php >=5.4.0
- laravel/framework 5.0.*
- vlucas/phpdotenv ~1.0
by James Brauman
laravel environment .env
Wallogit.com
2017 © Pedro Peláez
Simple per-environment .env files for Laravel 5.
Simple per-environment .env files for Laravel 5., (*1)
multidotenv is a package for Laravel 5 that provides functionality to load an additional environment-specific .env file., (*2)
Laravel 5 uses the dotenv package to load the .env file in the root directory. multidotenv extends Laravel 5 so that an additional .env file is loaded depending on the environment name., (*3)
For example, given a .env file containing:, (*4)
DB_HOST=localhost DB_DATABASE=my_project DB_USERNAME=root DB_PASSWORD=root
and a .env.testing file containing:, (*5)
DB_DATABASE=my_project_testing
when running the command php artisan migrate --env=testing the loaded enviroment variables would be:, (*6)
DB_HOST=localhost DB_DATABASE=my_project_testing DB_USERNAME=root DB_PASSWORD=root
Note that this package will always load '.env.' . $app->environment() if it exists. This is normally what APP_ENV is set to but can be overridden when using artisan by passing the --env flag. If neither of these are true Laravel 5 will use production by default., (*7)
You can leverage the 'always loading' functionality mentioned above to load a per-environment .env file for HTTP requests too., (*8)
For example in your .env file set your APP_ENV variable to foo. Now even over HTTP requests the .env.foo file will be loaded if it exists., (*9)
Add thesnackalicious/multidotenv to your composer.json file:, (*10)
"require": {
"thesnackalicious/multidotenv": "dev-master"
}
Use composer to install this package., (*11)
$ composer update
Add a bootrappers() function to the app/Http/Kernel.php file and the app/Console/Kernel.php file:, (*12)
/**
* Get the bootstrap classes for the application.
*
* @return array
*/
protected function bootstrappers()
{
$search = 'Illuminate\Foundation\Bootstrap\DetectEnvironment';
$replacement = 'TheSnackalicious\MultiDotEnv\DetectEnvironment';
return array_map(function($v) use ($search, $replacement) {
return $v == $search ? $replacement : $v;
}, $this->bootstrappers);
}
Simple per-environment .env files for Laravel 5.
MIT
laravel environment .env