title: Laravel 5.2 - extending the Validator class
body: <p>I am trying to override the <code>doReplacements</code> method in <code>Illuminate\Validation\Validator</code>. When I extend the native <code>Validator</code> and <code>Request</code> classes, I get this error: </p>
  
  <blockquote>
    <p>ReflectionException in Route.php line 270:</p>
    
    <p>Class App\Http\Requests\FooRequest does not exist</p>
  </blockquote>
  
  <p>This is what I did:</p>
  
  <ol>
  <li><p>Extend native <code>Illuminate\Validation\Validator</code>:</p>
  
  <pre><code>class MyCustomValidator extends Validator {
  
      protected function doReplacements($message, $attribute, $rule, $parameters) {
          //override this method
      }
  
  }
  </code></pre></li>
  <li><p>Use <code>MyCustomValidator</code> in an abstract extension of native <code>App\Http\Requests\Request</code>:</p>
  
  <pre><code>abstract class MyCustomRequest extends Request {
  
      //Override native method by injecting the extending validator
      protected function formatErrors( MyCustomValidator $validator )
      {
          return $validator-&gt;getMessageBag()-&gt;toArray();
      }
  }
  </code></pre></li>
  <li><p>Extend <code>MyCustomRequest</code> with concrete class:</p>
  
  <pre><code>class FooRequest extends MyCustomRequest
  {
  
      public function authorize()
      {
          return true;
      }
  
  
      public function rules()
      {
          return [
              // rules go here
          ];
      }
  }
  </code></pre></li>
  <li><p>Use the <code>FooRequest</code> in a controller method:</p>
  
  <pre><code>public function store(FooRequest $request) {
      //use the request and persist
  }
  </code></pre></li>
  </ol>
  
  <p><hr/>
  I am guessing I am lacking a required facade, provider, or container binding. I'm still learning these topics and don't understand them well enough to know a good next step.</p>
  
  <p>References:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/28417977/custom-validator-in-laravel-5">Custom validator in Laravel 5</a> -
  I followed the answer, but still got the same error. I want to know if this is is even remotely related to my problem before troubleshooting what I tried here.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/16897462/extending-custom-validation-class">Extending Custom Validation-Class</a> -
  Problem looks similar, answer suggests using <code>Validator::extend</code>, which I know can be done in <code>AppServiceProvider</code>, but ideally my code should be in its own vendor package. Again, not sure if relevant.</p></li>
  </ul>