Detect Environment with environment variables

Submitted by ashwin - 10 years ago

To setup configuration according to each environment you can set environmental variables. In this below example I am setting up an environmental variable "LARAVEL_ENV" with below values. staging as LARVEL_ENV staging production as LARVEL_ENV production Then in start.php under detect environment add the below code for getting the environment. You can add config files under respective folders.

$env = $app->detectEnvironment(function(){
        return getenv('LARAVEL_ENV') ? : '';
});


--app/config
    -database.php
    -staging 
        -database.php
    -production
        -database.php