title: upload image with laravel using ajax
body: <p>I have table user: </p>
  
  <ul>
  <li>id (int)</li>
  <li>firstname (string)</li>
  <li>lastName (string)</li>
  <li>email (string)</li>
  <li>login (string)</li>
  <li>password (string)</li>
  <li>image (text)</li>
  </ul>
  
  <p>I would like to insert image in my database using ajax jquery.</p>
  
  <p>But at the given database level it does not insert the data with the image.</p>
  
  <p>I try with this code but doesn't work.</p>
  
  <p><strong>Controller</strong>: </p>
  
  <pre><code> public function addUser(Request $request){
          $user = new User();
          $user-&gt;lastName = $request-&gt;lastName;
          $user-&gt;firstName = $request-&gt;firstName;
          $user-&gt;email = $request-&gt;email;
          $user-&gt;login = $request-&gt;login;
          $user-&gt;password = bcrypt($request-&gt;password);
  
          if($request-&gt;has('image') ) {
                  $file_local =  $request-&gt;file('image');
                  $extension = $request-&gt;file('image')-&gt;getClientOriginalExtension();
                  if($extension == 'jpg' || $extension == 'png' || $extension == 'jpeg'){
                    $name=$request-&gt;file('image')-&gt;getClientOriginalName();
                    $path = $file_local-&gt;storeAS('public/',$name);
  
                     $user-&gt;image = $name;
                }   
            }
          $user-&gt;save();
  
          return response()-&gt;json($user);   
      }
  </code></pre>
  
  <p><strong>View</strong>:</p>
  
  <pre><code>&lt;form enctype="multipart/form-data"&gt;
      &lt;div class="form-group"&gt;
                &lt;input type="text" id="lastName" class="form-control" placeholder="last Name" required /&gt;
  
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;input type="text" id="firstName" class="form-control" placeholder="name" required /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
              &lt;input type="email" id="email" class="form-control" placeholder="Email" required/&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;input type="text" id="login" class="form-control" placeholder="Login" required/&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;input type="password" id="password" class="form-control" placeholder="password" required/&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                 &lt;input type="file" id="image" class="form-control"  required  /&gt;
              &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>ajax</strong>:</p>
  
  <pre><code>$(document).on('click', "#creer_utilisateur", function() {
      var lastName= $('#lastName').val();
      var firstName = $('#firstName').val();
      var email = $('#email').val();
      var login = $('#login').val();
      var password = $('#password').val();
      var image = $('#image').val();
  
          success: function(data) {
              $.ajax({
                url: "{{action('UserController@addUser')}}",
                method: 'POST',
                data: {
                  lastName: lastName,
                  firstName: firstName,
                  email: email,
                  login: login,
                  password: password,
                  image: image
                },
                success: function(data) {
                alert('success');
  
                },
                error: function(){
                  alert('failed');
                }
              });
          }
        });
    });
  </code></pre>