Laravel 4: how can I get the environment value?

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

+44
laravel laravel-4
Feb 18 '13 at 12:02
source share
3 answers

You're in luck - it was just added to Beta 4 - see here for more details

Added App :: environment method.

Edit: these are now several different ways to get an environment variable like from Laravel 4.1

 App::environment() app()->environment() app()->env $GLOBALS['env'] // not recommended - but it is possible 

You can also check if the current environment is set to "local"

 App::isLocal() app()->isLocal() 

You can also check if the current environment is set to "test"

 App::runningUnitTests() app()->runningUnitTests() 
+66
Feb 18 '13 at 16:43
source share

You can also use app()->env .

+25
Feb 24 '13 at 1:12
source share

In Laravel 4 and 5, Laravel white papers suggest using:

 $environment = App::environment(); 

You can also pass arguments to the environment method to check if the environment matches the given value:

 if (App::environment('local')) { // The environment is local } if (App::environment('local', 'staging')) { // The environment is either local OR staging... } 
+11
Jun 24 '14 at 20:19
source share



All Articles