title: How to use sometimes rule in Laravel 5 request class
body: <p>I have the following request class:</p>
  
  <pre><code>&lt;?php namespace App\Http\Requests\User;
  
  use App\Http\Requests\Request;
  use Validator;
  use Session;
  use Auth;
  use App\User;
  
  class RegisterStep1Request extends Request {
  
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
      /**
       * Set up the validation rules
       */
      public function rules()
      {
          Validator::extend('valid_date', function($attribute, $value, $parameters)
          {
              $pieces = explode('/', $value);
              if(strpos($value, '/')===FALSE) {
                  return false;
              } else {
                  if(checkdate($pieces[1], $pieces[0], $pieces[2])) {
                      return true;
                  } else {
                      return false;
                  }
              }
          });
  
          return [
              'first_name' =&gt; 'required',
              'last_name' =&gt; 'required',
              'email' =&gt; 'required|email|unique:users,email',
              'dob' =&gt; 'required|regex:/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/|valid_date',
              'mobile' =&gt; 'required',
              'password' =&gt; 'required|confirmed'
          ];
      }
  
      public function messages()
      {
          return [
              'first_name.required' =&gt; 'The first name field is required.',
              'last_name.required' =&gt; 'The last name field is required.',
              'email.required' =&gt; 'The email address field is required.',
              'email.email' =&gt; 'The email address specified is not a valid email address.',
              'email.unique' =&gt; 'The email address is already registered with this website.',
              'dob.required' =&gt; 'The date of birth field is required.',
              'dob.regex' =&gt; 'The date of birth is invalid. Please use the following format: DD/MM/YYYY.',
              'dob.valid_date' =&gt; 'The date of birth is invalid. Please check and try again.',
              'mobile.required' =&gt; 'The mobile number field is required.',
              'password.required' =&gt; 'The password field is required.',
              'password.confirmed' =&gt; 'The confirm password field does not match the password field.'
          ];
      }
  
  }
  </code></pre>
  
  <p>I want to add the following sometimes rule:</p>
  
  <pre><code>Validator::sometimes('dob', 'valid_date', function($input)
  {
      return apply_regex($input-&gt;dob) === true;
  });
  </code></pre>
  
  <p>How would I add this to my request class?</p>
  
  <p>I have amended my rules method to the following:</p>
  
  <pre><code>public function rules()
  {
      Validator::extend('valid_date', function($attribute, $value, $parameters)
      {
          $pieces = explode('/', $value);
          if(strpos($value, '/')===FALSE) {
              return false;
          } else {
              if(checkdate($pieces[1], $pieces[0], $pieces[2])) {
                  return true;
              } else {
                  return false;
              }
          }
      });
  
      Validator::sometimes('dob', 'valid_date', function($input)
      {
          return apply_regex($input-&gt;dob) === true;
      });
  
      return [
          'first_name' =&gt; 'required',
          'last_name' =&gt; 'required',
          'email' =&gt; 'required|email|unique:users,email',
          'dob' =&gt; 'sometimes|required|regex:/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/|valid_date',
          'mobile' =&gt; 'required',
          'password' =&gt; 'required|confirmed'
      ];
  }
  </code></pre>
  
  <p>But I now get the following error when I submit the form:</p>
  
  <pre><code>FatalErrorException in Facade.php line 216:
  Call to undefined method Illuminate\Validation\Factory::sometimes()
  </code></pre>