title: Laravel 5.8 file upload using PUT method with ajax
body: <p>I'm trying to update a file using a PUT method with ajax. For whatever reason I can't send a request in my controller. I created a custom validator to check whether a file is missing or a certain input request is missing. It keeps on returning 422 file is missing and name is missing. What do I miss? Here's my code below.</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function() {
          $.ajaxSetup({
              headers: {
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
              }
          });
  
          $('#news_id').on('submit', function(e) {
              e.preventDefault();
              var data = new FormData();
              var newsletter_name = $('#newsletter_name').val();
              var newsletter_file = $('#newsletter_file')[0].files[0];
              data.append('newsletter_name', newsletter_name);
              data.append('newsletter_file', newsletter_file);
              var id = $('#hidden_id').val();
              console.log(newsletter_file);
              $.ajax({
                  url: '/admin/newsletter/' + id,
                  type: 'PUT',
                  data: data,
                  contentType: false,
                  processData: false,
                  beforeSend: function(data) {
  
                  },
                  success: function(data) {
                      console.log('success');
                  },
                  error: function(data) {
                      console.log(data)
                  },
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here's my html code</p>
  
  <pre><code>&lt;div class="container mt-5"&gt;
    &lt;div class="col-md-6"&gt;
         &lt;form action="" method="" enctype="multipart/form-data" id="news_id"&gt;
              @method('PUT')
              &lt;div class="form-group"&gt;
                  &lt;label for="newsletter_name"&gt;Name&lt;/label&gt;
                  &lt;input type="text" value="{{$newsletter-&gt;newsletter_name}}" name="newsletter_name" id="newsletter_name" class="form-control" placeholder="" aria-describedby="helpId"&gt;
                  &lt;input type="hidden" name="hidden_id" id="hidden_id" value="{{$newsletter-&gt;newsletter_id}}"&gt;
                  &lt;input type="hidden" name="_method" value="PUT"&gt;
              &lt;/div&gt;
              &lt;div class="input-group mb-3"&gt;
                  &lt;div class="custom-file"&gt;
                      &lt;input name="newsletter_file" type="file" class="custom-file-input" id="newsletter_file" aria-describedby="inputGroupFileAddon03"&gt;
                      &lt;label class="custom-file-label" for="newsletter_file"&gt;Choose file&lt;/label&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;button class="btn btn-primary btn-block" type="submit"&gt;UPDATE&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>