Created
          January 23, 2015 22:00 
        
      - 
      
- 
        Save Chapabu/3f1cb66ad9da06917e27 to your computer and use it in GitHub Desktop. 
    Binding environment specific providers in Laravel 5
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?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); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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