In a Laravel 4.2 framework I've created my own psr-4 php classes under app/mypackages.
Within one of those classes I'd like to check the environment like this:
$environment = Application::environment();
or
$environment = Cache::get('environment');
but neither is working. In the first example I receive the following error.
Non-static method Illuminate\Foundation\Application::environment() should not be called statically, assuming $this from incompatible context
The $app variable is not available in this context. What is best practice to obtain the environment and make the $app instance available to obtain the environment and some environment dependent variables in config folders?
Relatively new with Laravel so any insights much appreciated.
There are a few ways. Try these:
App::environment()
app()->environment()
app()->env
$GLOBALS['env'] // not recommended - but it is possible