title: how to read FormData object in Laravel
body: <p>I am trying to ajax submit form to a Laravel 5 controller method. I understand that in php, you can define a FormData object, append the input fields to the object and send it to the server where you can now extract the values using the input field names. </p>
  
  <p>Like so:</p>
  
  <pre><code>var form_data = new FormData();
  formdata.append('file_name', 'some_file_name_from_form.png');
  </code></pre>
  
  <p>When <code>form_data</code> is sent as the <code>data</code> in the ajax call, I can get the file in PHP by using the <code>$_FILES['file_name']['name'];</code>.</p>
  
  <p>So I tried this same logic in a Laravel controller method. I tried just to grab the name of the file in the <code>$request</code> object but only got null.</p>
  
  <p>My controller method:</p>
  
  <pre><code>public function postImage(Request $request)
  {
      $file = $request-&gt;get('file_name');
  
      dd($file);
  }
  </code></pre>
  
  <p>But when I <code>dd</code> the whole request, I see this weird object:</p>
  
  <blockquote>
    <p>array:1 [
      "file_name" => UploadedFile {#199
        -test: false
        -originalName: "work-fitness_00255959.png"
        -mimeType: "image/png"
        -size: 34215
        -error: 0
        #hashName: null
        path: "/tmp"
        filename: "phpVodsUg"
        basename: "phpVodsUg"
        pathname: "/tmp/phpVodsUg"
        extension: ""
        realPath: "/tmp/phpVodsUg"
        aTime: 2017-06-04 12:42:26
        mTime: 2017-06-04 12:42:26
        cTime: 2017-06-04 12:42:26
        inode: 17573243
        size: 34215
        perms: 0100600
        owner: 1000
        group: 1000
        type: "file"
        writable: true
        readable: true
        executable: false
        file: true
        dir: false
        link: false
      }
    ]</p>
  </blockquote>
  
  <p>Please how do I get the image sent through <code>FormData()</code> object in Ajax through it's name?</p>
  
  <p>Thanks for any help</p>