title: Returning a view with previous inputs using Laravel
body: <p>I have a form, when submitted, invokes an AJAX request. This ajax request performs back-end validation on the inputs. If an error is detected, it displays the error messages. <strong>So if the user fills out 30 fields, and one is not valid, I would like to return all those inputs with an error message.</strong></p>
  
  <p><strong>My Laravel Code:</strong></p>
  
  <pre><code>Route::post('/roa', function() {
  $m = Request::except('_token');
  $name = "form1_sections/" . $m['nextTab'] . "_form";//next view name
  $name2 = "form1_sections/" . $m['currentTab'] . "_form";//current view name
  
  $var= parse_str($m['inputs'], $output);//data from ajax is a string
  
  if ($m['currentTab']=='section2'){//i'm only doing validation on one section right now
  //to simplify the code.
      $rules = [
          'TB1_course.*' =&gt; 'required'
      ];
      $validator=Validator::make($output, $rules);
      if ($validator-&gt;passes()){//if no error, return the next view
          return ["view" =&gt; view("$name")-&gt; render(), "value"=&gt;1, "inputs"=&gt;$output];
      }
      return ["view" =&gt; view("$name2")-&gt;withInput($output)-&gt;withErrors($validator) -&gt; render(), "value"=&gt;1, "inputs"=&gt;$output];
  }
  return ["view" =&gt; view("$name") -&gt; render()];
  });
  </code></pre>
  
  <p><strong>My Ajax request:</strong></p>
  
  <pre><code>$('#form').on('submit', function (e) {
      var formData = $('#form').serialize();
      e.preventDefault();
      $.ajaxSetup({
          headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
      });
      $.ajax({
          type: 'POST',
          url: '/roa',
          dataType: 'json',
          data: {inputs: formData, nextTab: relatedTabID, currentTab: tabID},
          success: function(data){
              $('#tabShow').html((data.view));
          },
          error: function () {
              alert('error');
          }
      });
  });
  </code></pre>
  
  <p>I am successfully able to receive all the error messages, but the withInput($output) for some reason is not working. Thank you for all your help.</p>