title: Custom Middleware - Too Many Redirects - Laravel
body: <p>I want to create a custom middleware that only if the user is authenticated and the email is a certain email to access the /admin page.</p>
  
  <p>Although, when I specify my custom route and then a redirect it always says too many redirects..</p>
  
  <p><strong><em>Short Explanation.</em></strong> </p>
  
  <ol>
  <li>User Logs in -> redirected to /home. (Works)</li>
  <li>If user tries to access /admin and their email isn't like the one specified in the middleware, redirect to /home.</li>
  <li>If its true, let them in /admin</li>
  </ol>
  
  <p>My middleware is called 'admin.verify'</p>
  
  <p>The Routes file is automatically loaded and If I do redirect('/home') it automatically runs my middleware which is why I'm guessing it redirects to homepage too often.</p>
  
  <p><strong>Routes File:</strong></p>
  
  <pre><code>Route::get('/admin', 'AdminController@index')-&gt;name('admin.index');
  </code></pre>
  
  <p><strong>AdminController:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  class AdminController extends Controller
  {
      public function __construct(){
        $this-&gt;middleware(['auth', 'admin.verify']);
      }
  
  
      public function index(){
        return view('admin.test');
      }
  }
  </code></pre>
  
  <p><strong>Middleware:</strong> </p>
  
  <pre><code> public function handle($request, Closure $next)
      {
  
        if (Auth::check() &amp;&amp; Auth::User()-&gt;email == 'Tester@gmail.com') {
          return $next($request);
        } else {
          return redirect()-&gt;route('home');
        }
  </code></pre>
  
  <p><strong>My Home Route:</strong></p>
  
  <pre><code> GET|HEAD | home | home| App\Http\Controllers\HomeController@index | web,auth
  </code></pre>
  
  <p><strong>Home Controller:</strong></p>
  
  <pre><code>class HomeController extends Controller
  {
      /**
       * Create a new controller instance.
       *
       * @return void
       */
      public function __construct()
      {
          $this-&gt;middleware('auth');
      }
  
      /**
       * Show the application dashboard.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          return view('home');
      }
  }
  </code></pre>