Skip to content

Instantly share code, notes, and snippets.

@Chapabu
Created January 23, 2015 22:00
Show Gist options
  • Save Chapabu/3f1cb66ad9da06917e27 to your computer and use it in GitHub Desktop.
Save Chapabu/3f1cb66ad9da06917e27 to your computer and use it in GitHub Desktop.
Binding environment specific providers in Laravel 5
<?php namespace Farm\Providers;
use Illuminate\Support\ServiceProvider;
/**
* Class LocalServiceProviderProvider
*
* Service provider to allow us to register local environment specific providers (i.e. development dependencies).
*
* @package Farm\Providers
*/
class LocalServiceProviderProvider extends ServiceProvider
{
/**
* @var array
*/
private $providers = [
'Morrislaptop\LaravelFivePackageBridges\Bridges\GeneratorsServiceProvider',
];
/**
* Register the application services.
*
* @return void
*/
public function register()
{
if ($this->app->environment('local') && !empty($this->providers)) {
$this->bindLocalProviders();
}
}
/**
* Loop through the stored providers and register each of them with the IoC container.
*
* @return void
*/
private function bindLocalProviders()
{
foreach ($this->providers as $provider) {
$this->app->register($provider);
}
}
}
@jasondavis
Copy link

Nice idea. This is nice as well https://github.com/svenluijten/env-providers it basically does this but it creates a new providers.php config file in the config folder and allows to set service providers and faces/aliases for each environment group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment