title: How to create custom validation rule for dependent input fields in laravel
body: <p>In my input form, I have two fields; <code>momentFrom</code> &amp; <code>momentTo</code>. I need to put a validation which gives error message if any of the following criteria fails.</p>
  <ul>
  <li><code>momentFrom</code> is greater than or equal to <code>momentTo</code>.</li>
  <li><code>momentFrom</code> is less than now.</li>
  </ul>
  <p><strong>My code for storing the data:</strong></p>
  <pre><code>public function store(Request $request, Requisition $requisitionObj) {
      $momentFrom = strtotime($request-&gt;txtTravelDate . &quot; &quot; . $request-&gt;txtTimeFrom);
      $momentTo = strtotime($request-&gt;txtTravelDate . &quot; &quot; . $request-&gt;txtTimeTo);
  
      $timeValidation = $requisitionObj-&gt;validateTiming($momentFrom, $momentTo);
      if ($timeValidation['error']) {
          echo 'ERROR: ' . $timeValidation['message'];
          return view('requisitions.create');
      } else {
          /* store form data into requisition object */
          $requisitionObj-&gt;travel_date = $request-&gt;txtTravelDate;
          $requisitionObj-&gt;moment_from = $momentFrom;
          $requisitionObj-&gt;moment_to = $momentTo;
  
          $requisitionObj-&gt;save();
          
          return redirect()-&gt;route('requisitions.index');
      }
  }
  </code></pre>
  <p>I have seen laravel custom validation rules where only one field can be validated at a time. But in my scenario I need to check both fields at a time depending on each other. How can I achieve this?</p>
  <p>Thanks for any help in advance!</p>