I know that I can access the environment value using the global $env
variable, but is there the right way to get this value?
In Laravel 4 and 5, the Laravel official docs suggest using: $environment = App::environment();
You're in luck - this was just added in Beta 4 - see here for details
Added App::environment method.
Edit: these are now a number of various ways to get the environment variable as of Laravel 4.1
App::environment() app()->environment() app()->env $GLOBALS['env'] // not recommended - but it is possible
You can also specifically check for if the current environment is set to 'local'
App::isLocal() app()->isLocal()
You can also specifically check for if the current environment is set to 'testing'
App::runningUnitTests() app()->runningUnitTests()
You can also use app()->env
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With