title: What is the best way to replace a service in a Laravel Service Provider?
body: <p>I want to replace a service provided by the Laravel framework to one of my own, that extends that same Laravel service. In this specific case, I want to exchange the <code>BladeCompiler</code> service.</p>
  
  <p>The default <code>ViewServiceProvider</code> provided by Laravel does something like this:</p>
  
  <pre><code>use Illuminate\View\Engines\BladeCompiler;
  use Illuminate\View\Engines\CompilerEngine;
  
  ...
  
  public function registerBladeEngine($resolver)
  {
      $app = $this-&gt;app;
  
      $resolver-&gt;register('blade', function() use ($app)
      {
          $cache = $app['path.storage'].'/views';
  
          $compiler = new BladeCompiler($app['files'], $cache);
  
          return new CompilerEngine($compiler, $app['files']);
      });
  }
  </code></pre>
  
  <p>The only thing I need to do, is extend the provider, override the method and replace the compiler class. In this case, <code>My\View\Engines\BladeCompiler</code>.</p>
  
  <p>But to do that, I have to literally copy and paste all the function to my service provider, and just replace the <code>use</code> statement. That's a lousy way to do that, since any modification on that part of Laravel will break my app.</p>
  
  <p>What I really want to do, is create another class that extends the default blade compiler class, to add more features to it.</p>
  
  <p>Does anybody has a better idea?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><a href="https://github.com/laravel/framework/issues/2783" rel="noreferrer">I opened an issue</a> describing that problem, and Taylor will make a change for 4.1 that makes extending a service much more easier (at least the blade compiler).</p>