Laravel - detectEnvironment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); |
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.
@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
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.