2017 © Pedro Peláez
 

library multidotenv

Simple per-environment .env files for Laravel 5.

image

thesnackalicious/multidotenv

Simple per-environment .env files for Laravel 5.

  • Monday, June 1, 2015
  • by thesnackalicious
  • Repository
  • 1 Watchers
  • 6 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

multidotenv

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)

How it works

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)

What about HTTP requests?

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)

Installation

Add thesnackalicious/multidotenv to your composer.json file:, (*10)

"require": {
  "thesnackalicious/multidotenv": "dev-master"
}

Use composer to install this package., (*11)

$ composer update

Update Web Kernel and Console Kernal

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);
}

The Versions

01/06 2015

dev-master

9999999-dev

Simple per-environment .env files for Laravel 5.

  Sources   Download

MIT

The Requires

 

by James Brauman

laravel environment .env