title: Preventing login with Laravel's Auth
body: <p>I'm trying to prevent the user from logging in under some conditions.</p>
  
  <p>My idea is to perform some additional checks after using Laravel's Auth system.
  As for the login / register and recover password systems, everything works fine. But I can't seem to be able to log out the user and show a custom error in the login page.</p>
  
  <p>All I want to do is to show a custom "your account was suspended" message under the "email address" field, after verifying if the user was suspended or not.</p>
  
  <p><a href="https://i.stack.imgur.com/MptOP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MptOP.png" alt="enter image description here"></a></p>
  
  <p>My code (HomeController), as well as some of my solutions:</p>
  
  <pre><code>public function index(Request $request)
  {
          // After Laravel logs the user through its authentication system
          $user = Auth::user();
          if (!isset($user)) {
              return redirect('/');
  
          } else {    
              // we perform some checks of our own
              if ($user-&gt;suspended != 0) { // suspended by an administrator
                  $error = trans('errors_login.SUSPENDED_BY_ADMIN');
  
                 // return redirect()-&gt;route('logout', array('error_msg' =&gt; $error));
  
                 // return redirect()-&gt;route('logout')-&gt;withErrors('email','There was an error'); // trying to replace the "email" error
  
  
                 Auth::logout();
  
                 $error = ['loginError'=&gt; trans('errors_login.SUSPENDED_BY_ADMIN')];
                 return view('auth.login', $error);
  
  
              }
          }
  ...
  </code></pre>
  
  <p>Just to clarify what the "logout" route is:</p>
  
  <pre><code>Route::get('/logout', '\App\Http\Controllers\Auth\LoginController@logout');
  </code></pre>
  
  <p>I'm using Laravel's generated login view:</p>
  
  <pre><code>...
  
  &lt;div class="form-group row"&gt;
  &lt;label for="email" class="col-md-4 col-form-label text-md-right"&gt;E-Mail Address&lt;/label&gt;
  
  &lt;div class="col-md-6"&gt;
      &lt;input id="email" type="email" class="form-control{{ $errors-&gt;has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus&gt;
  
      @if ($errors-&gt;has('email'))
          &lt;span class="invalid-feedback" role="alert"&gt;
              &lt;strong&gt;{{ $errors-&gt;first('email') }}&lt;/strong&gt;
          &lt;/span&gt;
      @endif
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Nothing seems to work.
  I'm fairly new to Laravel, so I must be missing something.</p>
  
  <p>Thank you.</p>