title: Laravel middleware redirect loop
body: <p>I have a small dilema, i'm trying to make a login system that differentiates normal users from admin users using the laravel auth scaffolding.</p>
  
  <p>The problem is it goes in a infinite redirect loop in the middleware.</p>
  
  <p>After I press the login button it constantly redirects to a route and the question is, how can I solve this issue the "laravel way" or any other way for that matter.</p>
  
  <p>Here are my controllers:
  1. The basic home controller:</p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  class HomeController extends Controller
  {
     /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
      return view('home');
    }
  }
  </code></pre>
  
  <ol start="2">
  <li><p>The main admin controller - entry controller:</p>
  
  <pre><code> namespace App\Http\Controllers\Admin;
  
   use Illuminate\Http\Request;
   use App\Http\Controllers\Controller;
  
   class Start extends Controller
   {
  
    public function index(){
  
      return view('admin/index');
    }
  
  }
  </code></pre></li>
  <li><p>Login Controller(the default one from the auth scaffolding- modified by me, I removed the constructor): </p>
  
  <pre><code>    namespace App\Http\Controllers\Auth;
  
      use App\Http\Controllers\Controller;
      use Illuminate\Foundation\Auth\AuthenticatesUsers;
  
      class LoginController extends Controller
      {
        use AuthenticatesUsers;
        protected $redirectTo = '/home';
      }
  </code></pre></li>
  <li><p>The Middleware(redirect if RedirectIfAuthenticated):</p>
  
  <pre><code>        namespace App\Http\Middleware;
  
          use Closure;
          use Illuminate\Support\Facades\Auth;
  
          class RedirectIfAuthenticated
          {
             public function handle($request, Closure $next, $guard = null)
            {
              if (Auth::guard($guard)-&gt;check()) {
                if(Auth::user()-&gt;type == 2){//if user type is 1 then it's an admin.
                 return redirect()-&gt;route('web-admin');
                }else{
                  return redirect()-&gt;route('home');
               }
            }
          return $next($request);
        }
      }
  </code></pre></li>
  <li><p>The route file(web routes)</p>
  
  <pre><code>   Route::get('/', function () {
       return view('index');
     });
  
     Auth::routes();
     Route::middleware(['auth','guest'])-&gt;group(function() {
     Route::get('home',['as'=&gt;'home', 'uses'=&gt;'HomeController@index']);
     Route::get('web-admin',['as'=&gt;'web-admin', 'uses'=&gt;'Admin\Start@index']);
    });
  </code></pre></li>
  </ol>