Detecting the Environment with a Closure


Determining your environment is complicated.

You need more flexibility than simply checking hostnames to determine the environment for your Laravel application.


Use a Closure to determine your environment.

Edit bootstrap/start.php and use a Closure to do the detecting.

$env = $app->detectEnvironment(function()
    return getenv('_MY_ENVIRONMENT');


There's multiple ways to detect your environment.

The $app->detectEnvironment() method can take either an array (as illustrated in the Environment Specific Configurations recipe) or a Closure.

When an array of 'env' => array('hostnames') is provided, if no match is found then the environment defaults to "production".

But if a Closure is provided then it must return something. There is no default.

comments powered by Disqus