title: How to override a single function in a package for internal use with laravel?
body: <p>I would like to override a function in <code>vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php</code></p>
  
  <p>or to be precise a function iside the trait <code>Illuminate\View\Compilers\Concerns\CompilesEchos.php</code> used by that file. However I could not find very clear information on how to override packages. Could someone please help me understand how.</p>
  
  <p>I understand that I need to extend BladeCompiler</p>
  
  <p>Let's call it MyBladeCompiler</p>
  
  <pre><code>class MyBladeCompiler extends BladeCompiler
  {
      public function compileEchoDefaults($value)
      {
          return 'test';
          return preg_replace('/^(?=\$)(.+?)(?:\s+or\s+)(.+?)$/si', 'isset($1) ? $1 : $2', $value);
      }
  }
  </code></pre>
  
  <p>I now would like to register it as the new class to be used. I do understand this should be done in a serviceprovider, but how?</p>
  
  <pre><code>class AppServiceProvider extends ServiceProvider
  {
      public function boot()
      {
        $this-&gt;app-&gt;bind(BladeCompiler::class, MyBladeCompiler ::class);
      }
  }
  </code></pre>
  
  <p>this does not work</p>