if you are on 5.4 you can do under AppServiceProvider as follows:
public function register()
{
/*
* Sets third party service providers that are only needed on local/testing environments
*/
if ($this->app->environment() != 'production') {
/**
* Loader for registering facades.
*/
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
/*
* Load third party local aliases
*/
$loader->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
}
}
if you want full control under 5.5 you can do in the same AppServiceProvider:
public function register()
{
/*
* Sets third party service providers that are only needed on local/testing environments
*/
if ($this->app->environment() != 'production') {
/**
* Loader for registering facades.
*/
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
/*
* Load third party local providers
*/
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
/*
* Load third party local aliases
*/
$loader->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
}
}
and under composer.json in the extra:
"extra": {
"laravel": {
"dont-discover": [
"barryvdh/laravel-debugbar"
]
}
},
Then you are good to go and enable and disable via .env, if it's different of production it will be enabled (local, testing, etc..) if it's on production it will be automatically disabled.
Hope it helps, good luck!