title: Upload file via AJAX using laravel
body: <p>So basically I have a bootstrap modal pop up in which I want to upload a csv via jquery/ajax so I can parse through using PHP.</p>
  
  <p>I'm using laravel and this is currently my code:</p>
  
  <p>Modal:</p>
  
  <pre><code>&lt;div class="modal fade" id="uploadRecipientListModal" tabindex="-1" role="dialog"  aria-hidden="true"&gt;
      &lt;div class="modal-dialog" role="document"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;h5 class="modal-title text-center"&gt;Add Recipient List&lt;/h5&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                   &lt;form enctype="multipart/form-data" id="modal_form_id"  method="POST" &gt;
                      &lt;input type="file" name="documents"&gt;
                   &lt;/form&gt;
  
                   &lt;button id="uploadRecipientSubmit1"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>$( "#uploadRecipientSubmit1" ).click(function() {
      var postData = new FormData($("#modal_form_id")[0]);
  
      $.ajax({
              type:'POST',
              url:'recipient/upload-contact-list',
              processData: false,
              contentType: false,
              data : postData,
              success:function(data){
                console.log("File Uploaded" + data);
              },
              error:function(data){
                console.log("nope");
              }
  
          });       
  
  
  });
  </code></pre>
  
  <p>Controller PHP:</p>
  
  <pre><code>public function uploadContactList(Request $request)
  {
      if(\Illuminate\Support\Facades\Input::hasFile('documents')) {
  
         echo "Good";
  
      }
      else
      {
          echo "bad";
      }
  }
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>Route::post('/recipient/upload-contact-list', 'RecipientController@uploadContactList')-&gt;name('upload.contact.list');
  </code></pre>
  
  <p>Output in console:</p>
  
  <pre><code>File Uploadedbad
  </code></pre>
  
  <p>I just cant get access to the csv file i'm trying to upload so I can parse through it and upload the rows to the db.</p>
  
  <p>I've been struggling on this one for a while and tried multiple different things but cant get this working, can someone tell me where I'm going wrong?</p>
  
  <p>Thanks</p>