title: How to write and use a custom Laravel 5 Validator to validate multiple other fields values
body: <p>I have fields in a form that are only required IF two other fields are set TO SPECIFIC VALUES. This is not a case of required_with_all.  ITs not if they are set, its if they are set specifically.</p>
  
  <p>Example: <strong>'foo' => 'required_if_all:bar,2,bat,1'</strong>,</p>
  
  <p>I added a service provider: </p>
  
  <pre><code>&lt;?php namespace App\Providers;
  
  use Illuminate\Support\ServiceProvider;
  use Validator;
  
  class RequiredIfAllProvider extends ServiceProvider {
  
  /**
   * Bootstrap the application services.
   *
   * @return void
   */
  public function boot()
  {
      Validator::extend('required_if_all', function($attribute,$value,$parameters){
  
          // Is required if the list of key/value pairs are matching
          $pairs = [];
          foreach($parameters as $kp =&gt; $vp) $pairs[$kp] = $vp;
          foreach($pairs as $kp =&gt; $vp) if(\Request::input($kp) != $vp) return false;
          return true;
  
      });
  }
  
  /**
   * Register the application services.
   *
   * @return void
   */
  public function register()
  {
      //
  }
  
  }
  </code></pre>
  
  <p>And I make sure to use the  <code>App\Providers\RequiredIfAllProvider</code>; in the top of my custom Request file.</p>
  
  <p>If bar and bat are both set based on the parameters based to the validation, a new error should be added to the error bag.</p>
  
  <p>I have spent quite a bit on this.  Any ideas?</p>