Skip to content

Instantly share code, notes, and snippets.

@mabasic
Last active December 20, 2019 02:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mabasic/19c527702862039777d8 to your computer and use it in GitHub Desktop.
Save mabasic/19c527702862039777d8 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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
Copy link

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
Copy link
Author

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