Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4: how can I get the environment value?

I know that I can access the environment value using the global $env variable, but is there the right way to get this value?

like image 269
duality_ Avatar asked Feb 18 '13 12:02

duality_


People also ask

How can I get current environment in Laravel?

In Laravel 4 and 5, the Laravel official docs suggest using: $environment = App::environment();


2 Answers

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() 
like image 143
Laurence Avatar answered Sep 24 '22 20:09

Laurence


You can also use app()->env.

like image 27
kfriend Avatar answered Sep 22 '22 20:09

kfriend