Skip to content

Instantly share code, notes, and snippets.

@Sprocket
Last active December 29, 2015 14:49
Show Gist options
  • Save Sprocket/7686650 to your computer and use it in GitHub Desktop.
Save Sprocket/7686650 to your computer and use it in GitHub Desktop.
Laravel helper functions to test for local or production environments.
/**
* test for local environment
* @param string $env name of environment to test
* @return boolean
*/
function isLocal($env = 'local')
{
return app()->environment() == $env;
}
/**
* test for production environment
* @param string $env environment name to test
* @return boolean
*/
function isProduction($env = 'production')
{
return app()->environment() == $env;
}
/**
* test if the app is in dev mode
* @return boolean
*/
function isDev()
{
$env = app()->environment();
$local_names = ['local','dev','development'];
$remote_names = ['production','remote'];
// assume production fallback
return ( in_array($env, $local_names) OR ! in_array($env, $remote_names) ) ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment