title: Ajax 422 (Unprocessable Entity) Error for User Login Laravel
body: <p>I have a login modal and I am trying to use <code>Ajax</code> to check its validation. The issue I am running into is that the build in <code>Controllers</code> read the error message instead of the credentials and I get error <code>422 (Unprocessable Entity)</code> when user inputs wrong credentials.</p>
  
  <p><strong>Blade:</strong></p>
  
  <pre><code>$('#loginForm').submit(function () {
      event.preventDefault();
      initLogin($('#email').val(),$('#password').val());
  });
  </code></pre>
  
  <p><strong>JavaScript File:</strong></p>
  
  <pre><code>function initLogin(email, password) {
      $.ajax( {
          headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },    
          url:'loginModal',
          method:'POST',
          data: {
              email: email,
              password: password
          },    
          success: function( bolUpdated ) {
              window.location = "/home";
          },    
          fail: function() {
              alert('Incorrect');
          }     
      });   
  }
  </code></pre>
  
  <p><strong>Route:</strong></p>
  
  <p><code>Route::post( 'loginModal', 'Auth\LoginController@login' );</code></p>
  
  <p>Moving forward it is all build in <code>Laravel</code> functions which ends here:</p>
  
  <pre><code>public static function withMessages(array $messages)
  {
      return new static(tap(ValidatorFacade::make([], []), function ($validator) use ($messages) {
          foreach ($messages as $key =&gt; $value) {
              foreach (Arr::wrap($value) as $message) {
                  $validator-&gt;errors()-&gt;add($key, $message);
              }
          }
      }));
  }
  </code></pre>
  
  <p><code>$messages</code> has the error message <code>'These credentials do not match our records.'</code></p>
  
  <p>When I open the console log and look at the specifics of the error, it says:</p>
  
  <pre><code>{message: "The given data was invalid.",…}
  errors
  :
  {email: ["These credentials do not match our records."]}
  message
  :
  "The given data was invalid."
  </code></pre>
  
  <p>I am pretty new to <code>Laravel</code> and maybe this is not the correct way to approach this problem? </p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>[2018-03-12 21:58:56] local.INFO: array (
    'email' =&gt; '&lt;name@domain.com&gt;',
    'password' =&gt; '&lt;pass&gt;',
  )  
  </code></pre>