title: Custom Auth Middleware not redirecting properly for unauthorized user
body: <p>I have created a custom auth controller for recognising unauthorized user and redirect them to login path. If logged in the middlewre is working absolutely fine, but showing error if not logged in. Here is my code</p>
  
  <h2>Middleware:</h2>
  
  <pre><code>    class CheckUserAuthenticated
  {
      public function handle($request, Closure $next)
      {
          if(auth()-&gt;check()) {
              $user_id =  auth()-&gt;user()-&gt;id;
              define('authenticated_user_id' ,$user_id);
              return $next($request);
          }
          return redirect('login'); // this code is not working
      }
  }
  </code></pre>
  
  <h1>Error:</h1>
  
  <p><a href="https://i.stack.imgur.com/R8yCR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R8yCR.png" alt="enter image description here"></a></p>