title: trouble about laravel image uploading ajax
body: <p>it gives me an error : </p>
  
  <blockquote>
    <p>Call to a member function getClientOriginalExtension() on null</p>
  </blockquote>
  
  <p>here is my code</p>
  
  <p>form :</p>
  
  <pre><code>&lt;form id="regForm" role="form" enctype="multipart/form-data"&gt;
                      &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
                      &lt;div class="box-body"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="exampleInputEmail1"&gt;Title&lt;/label&gt;
                              &lt;input type="text" class="form-control" name="title" id="exampleInputEmail1" placeholder="Enter email"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="exampleInputPassword1"&gt;Type&lt;/label&gt;
                              &lt;input type="text" class="form-control" id="exampleInputPassword1" placeholder="Password"&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="exampleInputFile"&gt;File input&lt;/label&gt;
                              &lt;input type="file" name="image" id="exampleInputFile"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;&lt;!-- /.box-body --&gt;
  
                      &lt;div class="box-footer"&gt;
                          &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
  </code></pre>
  
  <p>and this is my ajax script </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          //alert($("#email").val());
      });
      $("#regForm").submit(function(){
          var selector = $(this);
  
          var form = selector.serializeArray();
          $.ajax({
              url: "{{URL::to('admin/snl_add_post')}}",
              type: "POST",
              data: form,
              dataType: "json",
              success: function(data){
                  if(!data.success)
                  {
                      $.each(data.errors, function(key, value){
                          selector.find("input[name="+key+"]").attr({"style":"border:1.5px solid red;"});
                      });
                  }
                  else
                  {
                      setTimeout(function(){
  
                          // Move to a new location or you can do something else
                          window.location.href = "{{URL::to('stickers_and_labels')}}";
  
                      }, 3000);
                  }
              }
          });
          return false;
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>and my controller</p>
  
  <pre><code>public function snl_add_post(){
          $response = array();
  
          $rules = array(
              'title' =&gt; 'required'
  
          );
  
          $validator = Validator::make(Input::all(), $rules);
  
          if($validator-&gt;fails()){
  
              $response["errors"] = $validator-&gt;messages();
  
              $response["success"] = FALSE;
  
              $response["msg"] = "Invalid Inputs";
          }
          else
          {
              $careers = new Careers;
  
              $careers-&gt;title = Input::get('title');
  
              $destinationPath = 'images/snl/';
  
              $extension = Input::file('image')-&gt;getClientOriginalExtension();
  
              $fileName = rand(11111,99999).'.'.$extension;
  
              Input::file('image')-&gt;move($destinationPath, $fileName);
  
              $careers-&gt;img_path = 'images/snl/'.$filename;
  
              $careers-&gt;save();
  
              if($careers){
  
                  $response["success"] = true;
                  $response["msg"] = "Success";
  
              }else{
  
                  $response["success"] = false;
                  $response["msg"] = "May error";
  
              }
          }
  
  
  
          return Response::json($response);
      }
  </code></pre>
  
  <p>i think my error is in ajax but i'm not really sure.
  any insight would be appreciated.</p>