title: Laravel, jQuery File upload error - "Call to a member function store() on array"
body: <p>I use this library to upload files <a href="https://github.com/blueimp/jQuery-File-Upload" rel="nofollow noreferrer">https://github.com/blueimp/jQuery-File-Upload</a></p>
  
  <p>When I try to upload a file I get an error: <code>"Call to a member function store() on array"</code> It seems like there's an issue with <code>$request-&gt;files</code> variable. When is's being passed to foreach loop, it does not return the correct index. </p>
  
  <p>Thank you for your help.</p>
  
  <p>Controller</p>
  
  <pre><code>public function upload(Request $request) {
        foreach($request-&gt;files as $file) {
          $filename = $file-&gt;store('library');
        }
      }
  </code></pre>
  
  <p>The output of <code>dd($request-&gt;files)</code></p>
  
  <pre><code>FileBag {#68
    #parameters: array:1 [
      "files" =&gt; array:1 [
        0 =&gt; UploadedFile {#45
          -test: false
          -originalName: "img_(17).jpg"
          -mimeType: "image/jpeg"
          -size: 1260662
          -error: 0
          path: "D:\xampp\tmp"
          filename: "phpD7B1.tmp"
          basename: "phpD7B1.tmp"
          pathname: "D:\xampp\tmp\phpD7B1.tmp"
          extension: "tmp"
          realPath: "D:\xampp\tmp\phpD7B1.tmp"
          aTime: 2018-05-30 16:10:02
          mTime: 2018-05-30 16:10:02
          cTime: 2018-05-30 16:10:02
          inode: 0
          size: 1260662
          perms: 0100666
          owner: 0
          group: 0
          type: "file"
          writable: true
          readable: true
          executable: false
          file: true
          dir: false
          link: false
          linkTarget: "D:\xampp\tmp\phpD7B1.tmp"
        }
      ]
    ]
  }
  </code></pre>
  
  <p>Response, when I use var_dump($file) in the controller within foreach loop.</p>
  
  <pre><code>array(1) {
    [0]=&gt;
    object(Symfony\Component\HttpFoundation\File\UploadedFile)#45 (7) {
      ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=&gt;
      bool(false)
      ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=&gt;
      string(12) "zdjęcie.jpg"
      ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=&gt;
      string(10) "image/jpeg"
      ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=&gt;
      int(7445)
      ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=&gt;
      int(0)
      ["pathName":"SplFileInfo":private]=&gt;
      string(24) "D:\xampp\tmp\php7175.tmp"
      ["fileName":"SplFileInfo":private]=&gt;
      string(11) "php7175.tmp"
    }
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;div id="dropZone"&gt;
    &lt;h1&gt;Drag &amp; Drop Files...&lt;/h1&gt;
    &lt;input type="file" id="fileupload" name="files[]" multiple&gt;
  &lt;/div&gt;
  &lt;h1 id="error"&gt;&lt;/h1&gt;&lt;br&gt;&lt;br&gt;
  &lt;h1 id="progress"&gt;&lt;/h1&gt;&lt;br&gt;&lt;br&gt;
  &lt;div id="files"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  $(function () {
     var files = $("#files");
  
     $("#fileupload").fileupload({
         url: '{{ route("libraryUpload") }}',
         dropZone: '#dropZone',
         dataType: 'json',
         autoUpload: false,
         headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
     }).on('fileuploadadd', function (e, data) {
         var fileTypeAllowed = /.\.(gif|jpg|png|jpeg)$/i;
         var fileName = data.originalFiles[0]['name'];
         var fileSize = data.originalFiles[0]['size'];
  
         if (!fileTypeAllowed.test(fileName))
              $("#error").html('Only images are allowed!');
         else if (fileSize &gt; 5000000)
             $("#error").html('Your file is too big! Max allowed size is: 5MB');
         else {
             $("#error").html("");
             data.submit();
         }
     }).on('fileuploaddone', function(e, data) {
          var status = data.jqXHR.responseJSON.status;
          var msg = data.jqXHR.responseJSON.msg;
  
          if (status == 1) {
              var path = data.jqXHR.responseJSON.path;
              $("#files").fadeIn().append('&lt;p&gt;&lt;img style="width: 100px; height: 100px;" src="'+path+'" /&gt;&lt;/p&gt;');
          } else
              $("#error").html(msg);
     }).on('fileuploadprogressall', function(e,data) {
          var progress = parseInt(data.loaded / data.total * 100, 10);
          $("#progress").html("Completed: " + progress + "%");
     });
  });
  &lt;/script&gt;
  </code></pre>