title: How to log user in after successful registration using Ajax ? Laravel 5.4
body: <p>I'm trying to use a Modal registration box using Ajax. It works but how can I log user in as well ?</p>
  
  <p>This is the overloaded <code>register</code> function in RegisterController.php:</p>
  
  <pre><code> /**
   * Handle a registration request for the application (overloaded).
   *
   * @param  \Illuminate\Http\Request  $request
   * @return \Illuminate\Http\Response
   */
  public function register(Request $request)
  {
      $validator = $this-&gt;validator($request-&gt;all());
  
      if ($validator-&gt;fails()) {
          $this-&gt;throwValidationException(
              $request, $validator
          );
      }
  
      $this-&gt;create($request-&gt;all());
  
      return response()-&gt;json();
  }
  </code></pre>
  
  <p>This is the standard function that ships with Laravel and logs user in upon registration.</p>
  
  <pre><code>/**
       * Handle a registration request for the application.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function register(Request $request)
      {
          $this-&gt;validator($request-&gt;all())-&gt;validate();
  
          event(new Registered($user = $this-&gt;create($request-&gt;all())));
  
          $this-&gt;guard()-&gt;login($user);
  
          return $this-&gt;registered($request, $user)
                          ?: redirect($this-&gt;redirectPath());
      }
  </code></pre>
  
  <p>And this is the AJAX call:</p>
  
  <pre><code>$(document).on('submit', '#formRegister', function(e) {  
              e.preventDefault();
  
              $('input+small').text('');
              $('input').parent().removeClass('has-error');
  
              $.ajax({
                  method: $(this).attr('method'),
                  url: $(this).attr('action'),
                  data: $(this).serialize(),
                  dataType: "json"
              })
              .done(function(data) {
                  console.log(data);
                  $('.alert-success').removeClass('hidden');
                  $('#myModal').modal('hide');
              })
              .fail(function(data) {
                  console.log(data);
                  $.each(data.responseJSON, function (key, value) {
                      var input = '#formRegister input[name=' + key + ']';
                      $(input + '+small').text(value);
                      $(input).parent().addClass('has-error');
                  });
              });
          });
  </code></pre>
  
  <p>How can I log user in and redirect to <code>/home</code></p>