Auto-detection and configuration of the environment with multiple env files
jarnix/laravel-auto-environment is a Laravel package for auto-detection and configuration of the environment with multiple env files.
It currently has 1 GitHub stars and 578 downloads on Packagist (latest version 1.0.6).
Install it with composer require jarnix/laravel-auto-environment.
Discover more Laravel packages by jarnix
or browse all Laravel packages to compare alternatives.
Last updated
Detects the application environment from a env file or the hostname or http host. A .env file will always overwrite any other file (default Laravel's behavior)
Use this code by adding this in bootstrap/app.php
\Jarnix\LaravelAutoEnvironment\Loader::init($app, [
'envsFolder' => '/config',
'hostLocalRegexp' => '/vagrantphp7',
'urlLocalRegexp' => '/l\.webedev\.com/',
'urlTestingRegexp' => '/test\.webedev.com/',
'urlProductionRegexp' => '/www\.webedev.com/'
]);
Put your different configuration files in the app's "/config" folder, or another folder (specified as the 'envsFolder' parameter) :
You can customize these parameters:
You can also force the environment you want by creating a file called "env" at the root of the app, containing the environment you want to load.
This code will then load the "env" file that you want in the "envsFolder" folder. For example: if the file's content is "local" => the file : /config/.env.local will be loaded
If you haven't created a env file, you can still obviously force the environment by using:
php artisan --env=testing
And you can use a .env file as usual, this will then bypass this code.