Laravel Environment is a library designed to be used in conjunction with Laravel. It enables the user to load a different .env file from the original. The coolest thing about this library is that it provides different methods for you to do this.
There are currently 3 methods:
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable($system_environment_variable_name, $default_value = 'local')
//Loads an environment file according to the value of a system environment variable
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromFile($filename)
//Loads an environment file explicitly, stating the file path
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(Callable $callable)
//Enables the user to enter a custom method for loading the environment file
To use this library is very simple, just call Laravel Environment before return $app;
in the bootstrap/app.php
file:
...
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
return $app;
We assume in this example that the system environment variable MYAPP_ENV exists and has the value 'production'.
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the environment file .env.production
We assume in this example that the system environment variable MYAPP_ENV does not exist.
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the .env.local environment file. When the system environment variable does not exist, then it takes $default_value.
//By default $default_value is set to 'local'.
We assume in this example that the system environment variable MYAPP_ENV does not exist, and $default_value will be 'acme'.
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV', 'acme');
//Will load the .env.acme environment file. When the system environment variable does not exist, then it takes $default_value.
\Ejetar\LaravelEnvironment::fromFile('.env.local');
//Load the .env.local file explicitly
Loading the server IP-based environment file:
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(function(){
switch($_SERVER['SERVER_ADDR']) {
case '1.2.3.4':
return '.env.local';
break;
case '5.6.7.8':
return '.env.production';
break;
default:
return '.env.other';
}
});
composer require ejetar/laravel-environment
Nothing for now...
Contribute to this wonderful project, it will be a pleasure to have you with us. Let's help the free software community. You are invited to incorporate new features, make corrections, report bugs, and any other form of support. Don't forget to star in this repository! π
This library is a open-source software licensed under the MIT license.