title: Laravel 5 access to ajax Post Data
body: <p>I'm trying to receive data from a form through AJAX on Laravel 5.</p>
  
  <p>JavaScript code:</p>
  
  <pre><code>event.preventDefault();     // Disable normal behaviour of the element (Form)
  
  var formData = {
      form: $("#newCustomerForm").serialize()     // Transmit all input data of the form serialized
  }
  
  console.log(formData);      // Log to the console the Input data
  
  $.ajax({
      type: 'post',           // POST Request
      url: 'save',            // Url of the Route (in this case user/save not only save)
      data: formData,         // Serialized Data
      dataType: 'json',       // Data Type of the Transmit
      beforeSend: function (xhr) {
          // Function needed from Laravel because of the CSRF Middleware
          var token = $('meta[name="csrf_token"]').attr('content');
  
          if (token) {
              return xhr.setRequestHeader('X-CSRF-TOKEN', token);
          }
      },
      success: function (data) {
          // Successfuly called the Controler
  
          // Check if the logic was successful or not
          if (data.status == 'success') {
              console.log('alles ok');
          } else {
              console.log(data.msg);
          }
      },
      error: function (data) {
          // Error while calling the controller (HTTP Response Code different as 200 OK
          console.log('Error:', data);
      }
  });
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::post ('user/save', 'CustomerController@createNewCustomer');
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function createNewCustomer (Request $request)
  {
      $inputArray = $request-&gt;all();
  
      print_r ($inputArray['form']);
  
      // Set JSON Response array (status = success | error)
      $response = array ('status' =&gt; 'success',
                         'msg' =&gt; 'Setting created successfully',);
      // Return JSON Response
  
      return response ()-&gt;json ($response);
  }
  </code></pre>
  
  <p>In the network tab I can see how the parameters look like:</p>
  
  <pre><code>radio-inline-left=on&amp;firstname=sdsd&amp;private_lastname=&amp;private_title=&amp;private_birthdate=&amp;private_email=&amp;business_email=&amp;private_phone=&amp;business_phone=&amp;private_mobile=&amp;business_mobile=&amp;brand=&amp;business_job_title=&amp;business_address_street=sdsd&amp;business_address_po_box=&amp;business_address_addon_1=&amp;business_address_addon_2=&amp;private_zip=&amp;private_location=&amp;business_address_street=&amp;business_address_po_box=&amp;business_address_addon_1=&amp;business_address_addon_2=&amp;private_zip=&amp;private_location=&amp;source=social_media&amp;source=&amp;availability=on&amp;additional-info={"status":"success","msg":"Setting created successfully"}
  </code></pre>
  
  <p>I also tried to access the data with <code>$request-&gt;input('name of the field')</code> but then it's always empty.</p>
  
  <p>Does anybody have an idea what i'm doing wrong?</p>