title: laravel create one rule with query based on several fields from the form
body: <p>I'm creating a simple reservation system and I need to check that car is available.
  I'm gonna create a custom rule but I have following problems:<br>
  1. I need to pass an argument few values from form to passes method: date, time_form, time_to, car_id. The first and second question get excited because;<br>
  2. I'm not sure how and where to call that method in the controller if I have to use it in a few input's .<br>
  3. I suppose I need to create a query to check that car exist. In pure php I create query but I'm not sure that my "laravel" style query in god:</p>
  
  <pre class="lang-php prettyprint-override"><code>$result = Reservation::where(function ($query) use ($request) {
              $query-&gt;whereBetween('time_from', [$request-&gt;input('time_from), $request-&gt;input('time_to')])
                  -&gt;orWhereBetween('time_to', [$request-&gt;input('time_from'), $request-&gt;input('time_to')]);
                 })-&gt;where(function ($query) use ($request) {$query
              -&gt;whereBetween($request-&gt;input('time_from'), ['time_from','time_to'])
              -&gt;orWhereBetween($request-&gt;input('time_to'), ['time_from','time_to']);
                 })
              -&gt;where('date',$request-&gt;input('date'))
              -&gt;where('car_id',$request-&gt;input('car_id'));
  </code></pre>
  
  <p>and pure php</p>
  
  <pre class="lang-php prettyprint-override"><code>$sql1 = "select * from reservation 
          where ('$time_from' BETWEEN time_from AND time_to or '$time_to' BETWEEN time_from AND time_to) 
          and (time_from BETWEEN '$time_from' AND '$time_to' or time_to BETWEEN '$time_from' AND '$time_to')              
          and car_id = '$car_id'";
  </code></pre>
  
  <p>I'm newbie in laravel so I am asking you for understanding. I'm asking for some advice. Maybe is some better way to do this.</p>