Check whether the app is in a specific environment

Submitted by mattstauffer - 6 years ago

Sometimes you want to perform a chunk of code dependent on the environment. This trick makes it easy to check against multiple environments and returns a boolean.

if (App::environment(['local', 'staging'])) {
    Route::get('test', 'TestController');   
}

// or 

if (app()->environment(['local', 'staging'])) {
    Route::get('test', 'TestController');
}