title: Laravel Validation Large JSON too slow
body: <p>I am working on a hotel application, in which I can receive large amounts of data in JSON format to update the database records.</p>
  <p>The JSON structure is as follows ( reduced example ):</p>
  <pre><code>[
  {
      &quot;combination_plan_id&quot;: 1,
      &quot;details&quot;: [
          {
              &quot;date&quot;: &quot;2022-04-20&quot;,
              &quot;price&quot;: 15000,
              &quot;checkin_denied&quot;: 0,
              &quot;minimum_stay&quot;: 3,
              &quot;sales_closed&quot;: 0,
              &quot;days_release&quot;: 1
          },
          {
              &quot;date&quot;: &quot;2022-04-21&quot;,
              &quot;price&quot;: 15000,
              &quot;sales_closed&quot;: 0,
              &quot;checkin_denied&quot;: 0,
              &quot;minimum_stay&quot;: 3
          }
      ]
  },
  {
      &quot;combination_plan_id&quot;: 3,
      &quot;details&quot;: [
          {
              &quot;date&quot;: &quot;2022-04-20&quot;,
              &quot;price&quot;: 15000,
              &quot;sales_closed&quot;: 0,
              &quot;checkin_denied&quot;: 0,
              &quot;minimum_stay&quot;: 3,
              &quot;days_release&quot;: 1
          },
          {
              &quot;date&quot;: &quot;2022-04-21&quot;,
              &quot;price&quot;: 15000,
              &quot;checkin_denied&quot;: 0,
              &quot;minimum_stay&quot;: 3,
              &quot;days_release&quot;: 1
          }
      ]
  }
  </code></pre>
  <p>]</p>
  <p>For each item of each details I need to verify that the date is mandatory and equal or later than today and for the rest of the fields that are optional, other validations of values, that's the least of it, since they are simple validations.</p>
  <p>The thing is that at the beginning I used the ValidationRequest, then I tried with the Validator Facade, and in both cases it takes a lot of time (about 10 minutes) when I process a large amount of data. We are talking that I am testing with a json of more than 700.000 lines.
  Looking for solutions, I created my own validation, going through each of the nodes with foreach and evaluating the data manually, and my surprise came when I got the time down to 2 seconds!
  Obviously I'm happy with the time it takes to validate the data manually, but very annoyed to know why the Laravel validator takes so long.
  I would like to know if I'm doing something wrong and that's why the huge delay in the process or if someone understands the reason for the big difference, what does laravel do to take so long.</p>
  <p>Here is the validator code and also the manual validation code</p>
  <p>Validator code:</p>
  <pre><code>$validator = Validator::make($request-&gt;all(), [
          '*.details.*.date'           =&gt; ['required', 'date_format:Y-m-d', 'after_or_equal:today', 'before_or_equal:' . Carbon::now()-&gt;addYears(2) ],
          '*.details.*.sales_closed'    =&gt; 'int|min:0|max:1',
          '*.details.*.minimum_stay'   =&gt; 'int|min:0',
          '*.details.*.checkin_denied' =&gt; 'int|min:0|max:1',
          '*.details.*.days_release'   =&gt; 'int|min:0',
          '*.details.*.price'          =&gt; 'int|min:0',
      ]);
  
      if ($validator-&gt;fails()) {
          return response()-&gt;json( $validator-&gt;errors() );
      }
  </code></pre>
  <p>Manual validation:</p>
  <pre><code>    $currentDateFormated    = Carbon::now()-&gt;format( 'Y-m-d' );
      $maxAllowedDateFormated = Carbon::now()-&gt;addYears(2)-&gt;format( 'Y-m-d' );
  
      $detailErrors = [];
      foreach ( $data as $combiData ) {
          $jsonCombiIds []= $combiData[ 'combination_plan_id' ];
  
          foreach ( $combiData[ 'details' ] as $key =&gt; $detail ) {
              if ( isset( $detail[ 'date' ] ) ) {
                  if ( $detail[ 'date' ] &lt; $currentDateFormated ) {
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }elseif ($detail[ 'date' ] &gt; $maxAllowedDateFormated ) {
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser posterior a dos años&quot;;
                  }
  
                  if( isset( $detail[ 'sales_closed' ] ) &amp;&amp; ( $detail[ 'sales_closed' ] &lt; 0 || $detail[ 'sales_closed' ] &gt; 1 ) ){
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Cierre de ventas (&quot; . $detail[ 'sales_closed' ] . &quot;) tiene que ser 0 o 1 - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }
  
                  if( isset( $detail[ 'minimum_stay' ] ) &amp;&amp; $detail[ 'minimum_stay' ] &lt; 0 ){
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Mínimo de estancias (&quot; . $detail[ 'minimum_stay' ] . &quot;) tiene que ser mayor o igual a 0 - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }
  
                  if( isset( $detail[ 'checkin_denied' ] ) &amp;&amp; ( $detail[ 'checkin_denied' ] &lt; 0 || $detail[ 'checkin_denied' ] &gt; 1 ) ){
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Checkin permitido (&quot; . $detail[ 'checkin_denied' ] . &quot;) tiene que ser 0 o 1 - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }
  
                  if( isset( $detail[ 'days_release' ] ) &amp;&amp; $detail[ 'days_release' ] &lt; 0 ){
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Días de release (&quot; . $detail[ 'days_release' ] . &quot;) tiene que ser mayor o igual a 0 - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }
  
                  if( isset( $detail[ 'price' ] ) &amp;&amp; $detail[ 'price' ] &lt; 0 ){
                      $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Precio (&quot; . $detail[ 'price' ] . &quot;) tiene que ser mayor o igual a 0 - Fecha (&quot; . $detail[ 'date' ] . &quot;) no puede ser anterior a hoy&quot;;
                  }
              } else{
                  $detailErrors[] = &quot;CombinationPlanId &quot; . $combiData[ 'combination_plan_id' ] . &quot; - Fecha no establecida&quot;;
              }
          }
      }
  
      $validationFails = [];
  
      if( !empty( $detailErrors ) ){
          $validationFails[] = $detailErrors;
      }
  </code></pre>
  <p>Thank you very much for your help.</p>