title: File uploading using ajax call in laravel 5.4
body: <p>In my application I need to upload a cover image for a dish. </p>
  
  <p><strong>Here's my AJAX call:</strong></p>
  
  <pre><code>$('#addDishForm').submit(function(e) {
      e.preventDefault();
      var el = $(this);
      var formAction = el.attr('action');
      var formValues = el.serialize();
      console.log(formValues);
  
      $.ajax({
          type: 'POST',
          url: '/admin/menu',
          data: new FormData(el[0]),
          success: function (data) {
              console.log(data);
          },
          error: function(data) {
              console.error(data);
          }
      });
  }); 
  </code></pre>
  
  <p>I have an error as a result <code>return</code> from controller in console.</p>
  
  <blockquote>
    <p>Uncaught TypeError: Illegal invocation</p>
  </blockquote>
  
  <p>What is the workaround?</p>
  
  <p><strong>Here is the controller's method:</strong></p>
  
  <pre><code>public function store(Request $request)
  {
      if($request-&gt;hasFile('cover_image'))
      {
          return response()-&gt;json([ 'success' =&gt; true, 'message' =&gt; 'File exists' ]);
      }
      else 
      {
          return response()-&gt;json([ 'success' =&gt; false, 'message' =&gt; 'File doesn\'t exist' ]);
      } 
  }
  </code></pre>
  
  <p>A route:</p>
  
  <pre><code>Route::middleware('auth')-&gt;prefix('/admin')-&gt;namespace('Admin')-&gt;group(function () {
      // other routes ...
      Route::post('/menu', 'MenuController@store');
      // other routes ...
  });
  </code></pre>
  
  <p><strong>Here's the form:</strong></p>
  
  <pre><code>{!! Form::open([ 'method' =&gt; 'POST', 'enctype' =&gt; 'multipart/form-data', 'id' =&gt; 'addDishForm' ]) !!}
      // other form controls ...
      {{ Form::file('cover_image', [ 'class' =&gt; 'dropify', 'data-max-file-size' =&gt; '2M' ]) }}
      // other form controls ...
  {!! Form::close() !!}
  </code></pre>