Multiple Nvironment Portable

Asked

Viewed 309 times

2

How do I create multiple Nvironment and mute at runtime the Nvironment I’m using in Laravel 5.5?

1 answer

1


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

For example:

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

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

Via 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 the artisanrunning with certain environment configuration, which is via the option --env.

php artisan --env=testing

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

Behold:

$testing = '.env.testing';

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.