Multiples environment laravel

2

How do I create multiple environment and mute at runtime the environment I'm using in laravel 5.5?

    
asked by anonymous 27.10.2017 / 21:03

1 answer

1

According to the documentation, you can create manual scans of which environment is via the App::envinroment() method.

For example:

if (App::environment('local')) {
    // Ambiente local
}

if (App::environment(['local', 'staging'])) {
    // Ambiente de Teste!
}

Using the variable APP_ENV , you can change the name of the environment you want to use.

For example:

APP_ENV=testing

There is still a way to force artisan to run with a given environment setting, which is through the --env option.

php artisan --env=testing

It seems that the solution adopted in some versions of Laravel 5. * is to manually overwrite the .env file manually. You can do this in the AppServiceProvider, checking for example if a particular file exists to apply the modifications.

See:

$testing = '.env.testing';

if (File::exists(base_path($testing)) {

   $dotenv = new \Dotenv\Dotenv(base_path(), $testing);
   $dotenv->overload(); 
}

Note : Dotenv\Dotenv is the class responsible for loading .env values.

    
01.11.2017 / 13:58