Skip to content

Instantly share code, notes, and snippets.

@mabasic
Last active Dec 20, 2019
Embed
What would you like to do?
Laravel - detectEnvironment
<?php
/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/
if(!function_exists('getEnvironment'))
{
function getEnvironment()
{
$environmentList = [
'local' => ['homestead'],
'windows' => ['mabasic-laptop', 'mabasic-box']
];
$appEnv = function ()
{
return $_ENV['APP_ENV'];
};
return isset($_ENV['APP_ENV']) ? $appEnv : $environmentList;
}
}
$env = $app->detectEnvironment(getEnvironment());
@mabasic

This comment has been minimized.

Copy link
Owner Author

@mabasic mabasic commented Sep 7, 2014

This function enables you to use the default Laravel way of handling environments based on hostnames, but if it finds APP_ENV then it uses that.

@r115

This comment has been minimized.

Copy link

@r115 r115 commented Mar 8, 2015

Came here on a copy/paste spree :-)

Got hit by a bug on line 29 of this gist. For the sake of the other copy pasters could you fix that.

Thanks anyway,helped me a great deal.

@mabasic

This comment has been minimized.

Copy link
Owner Author

@mabasic mabasic commented Apr 12, 2015

@nandwabee xD Did not see your comment until now. I've fixed the code now.

Happy copy/pasting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment