title: Serialize the Form dynamic image field using ajax in laravel 5.6
body: <p>Hi i want to serialize the form using ajax in laravel but i'm getting the error i don't know why trying hard on searching the internet but not able to understand what is the error and what is the real problem .</p>
  
  <p>Here is my view </p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta name="_token" content="{{ app('Illuminate\Encryption\Encrypter')-&gt;encrypt(csrf_token()) }}" /&gt;
      &lt;title&gt;Laravel Multiple File Upload Example&lt;/title&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="container"&gt;
      @if (count($errors) &gt; 0)
          &lt;div class="alert alert-danger"&gt;
              &lt;strong&gt;Whoops!&lt;/strong&gt; There were some problems with your input.&lt;br&gt;&lt;br&gt;
              &lt;ul&gt;
                  @foreach ($errors-&gt;all() as $error)
                      &lt;li&gt;{{ $error }}&lt;/li&gt;
                  @endforeach
              &lt;/ul&gt;
          &lt;/div&gt;
      @endif
  
      @if(session('success'))
          &lt;div class="alert alert-success"&gt;
              {{ session('success') }}
          &lt;/div&gt;
      @endif
  
      &lt;h3 class="jumbotron"&gt;Laravel Multiple File Upload&lt;/h3&gt;
      &lt;form method="post"  id="d-form" enctype="multipart/form-data"&gt;
          {{csrf_field()}}
  
          &lt;div class="input-group control-group increment" &gt;
              &lt;input type="file" name="filename[]" class="form-control"&gt;
              &lt;input type="text" name="descri[]" class="form-control"&gt;
              &lt;div class="input-group-btn"&gt;
                  &lt;button class="btn btn-success" type="button"&gt;&lt;i class="glyphicon glyphicon-plus"&gt;&lt;/i&gt;Add&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="clone hide"&gt;
              &lt;div class="control-group input-group" style="margin-top:10px"&gt;
                  &lt;input type="file" name="filename[]" class="form-control"&gt;
                  &lt;input type="text" name="descri[]" class="form-control"&gt;
                  &lt;div class="input-group-btn"&gt;
                      &lt;button class="btn btn-danger" type="button"&gt;&lt;i class="glyphicon glyphicon-remove"&gt;&lt;/i&gt; Remove&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;button type="submit" class="btn btn-primary" style="margin-top:10px"&gt;Submit&lt;/button&gt;
  
      &lt;/form&gt;
  &lt;/div&gt;
  
  
  &lt;script type="text/javascript"&gt;
      $(function() {
          $.ajaxSetup({
              headers: {
                  'X-XSRF-Token': $('meta[name="_token"]').attr('content')
              }
          });
      });
  
      $(document).ready(function() {
  
          $(".btn-success").click(function(){
              var html = $(".clone").html();
              $(".increment").after(html);
          });
  
          $("body").on("click",".btn-danger",function(){
              $(this).parents(".control-group").remove();
          });
          $("#submit").submit(function(){
              var formdata = $("#d-form").serialize();
              $.ajax({
                  type: 'POST',
                  url: '/form',
                  data: formdata,
                  success: function (data) {
                      alert(data);
                  },
              });
              stay.preventDefault();
          });
  
      });
  
  
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my controller in which i'm getting the images and saving it using json. </p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use App\Form;
  use Illuminate\Http\Request;
  
  class FormController extends Controller
  {
      public function create(Request $request)
      {
          $this-&gt;validate($request, [
              'filename' =&gt; 'required',
              'filename.*' =&gt; 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
          ]);
          return view('create');
      }
      public function store(Request $request)
  
      {
  
          $this-&gt;validate($request, [
  
              'filename' =&gt; 'required',
              'filename.*' =&gt; 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
  
          ]);
  
          if($request-&gt;hasfile('filename'))
          {
  
              foreach($request-&gt;file('filename') as $image)
              {
                  $name=$image-&gt;getClientOriginalName();
                  $image-&gt;move(public_path().'/images/', $name);
                  $data[] = $name;
              }
          }
  
          $form= new Form();
          $form-&gt;filename=json_encode($data);
  
  
          $form-&gt;save();
  
          return  "Your images has been successfully";
      }
  }
  </code></pre>
  
  <p>Finally here is my routes.</p>
  
  <pre><code>Route::get('form','FormController@create');
  Route::post('form','FormController@store');
  </code></pre>