title: Way to optimize this middleware code / make shorter
body: <p>I want to improve in the code I write, I tried several things but this one seems to be the least worst, but I have the feeling that it is not optimized at all, lots of code repetition.</p>
  <p>Do you have any ideas for optimization ? This is a middleware to check if user is ban or inactive</p>
  <pre><code>public function handle(Request $request, Closure $next)
      {
          if (auth()-&gt;check())  {
  
              if (auth()-&gt;user()-&gt;isBanned()) {
                  auth()-&gt;logout();
                  $request-&gt;session()-&gt;invalidate();
                  $request-&gt;session()-&gt;regenerateToken();
  
                  return redirect()-&gt;route('auth.login')-&gt;with('error', trans('login.banned'));
              }
  
              if(auth()-&gt;user()-&gt;isInactive()) {
                  auth()-&gt;logout();
                  $request-&gt;session()-&gt;invalidate();
                  $request-&gt;session()-&gt;regenerateToken();
  
                  return redirect()-&gt;route('auth.login')-&gt;with('error', trans('login.inactive'));
              }
          }
  
  
  
          return $next($request);
      }
  </code></pre>