title: Laravel 5.4: custom Middleware not working in route
body: <p>I created the following Middleware to check user session</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Closure;
  
  class Checkusersession
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          if (!$request-&gt;session()-&gt;has('admin_name')) {
              // user value cannot be found in session
              return redirect('adminlogin');
          }
  
          return $next($request);
      }
  }
  </code></pre>
  
  <p>this is my route:</p>
  
  <pre><code> Route::get('webadmin',['middleware' =&gt; 'usersession','Admin_controller@index']);
  </code></pre>
  
  <p>this is my kernel.php</p>
  
  <pre><code> protected $routeMiddleware = [
      'auth' =&gt; \Illuminate\Auth\Middleware\Authenticate::class,
      'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'bindings' =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
      'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,
      'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
      'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
      'usersession' =&gt; \App\Http\Middleware\Checkusersession::class,
  ];
  </code></pre>
  
  <p>this is my controller method that creates session:</p>
  
  <pre><code>public function auth_admin(Request $request)
  {
      $admin_emai = $request-&gt;input('admin_email');
      $admin_password = $request-&gt;input('admin_password');
  
      $checklogin = DB::table('admin_login')
          -&gt;select('admin_id','admin_email','admin_name')
          -&gt;where([
              'admin_email' =&gt; $admin_email,
              'admin_password' =&gt; $admin_password
          ])-&gt;first();
  
      if (count($checklogin) &gt; 0) {
          $request-&gt;session()-&gt;put('admin_id',$checklogin-&gt;admin_id);
          $request-&gt;session()-&gt;put('admin_name',$checklogin-&gt;admin_name);
          $request-&gt;session()-&gt;put('admin_email',$checklogin-&gt;admin_email);
  
          return redirect()-&gt;action('Admin_controller@webadmin');
      } else {
          return redirect()-&gt;action('Admin_controller@admin_login_page')-&gt;with('status','Incorrect Email ID or Password');
      }
  }
  </code></pre>
  
  <p>I want the Middleware to check if the session (admin_name) exists or not. If not, redirect the user to the login page. but it is not working. if I access the webadmin (dashboard) directly from url, it gives me access even if the session is not set. Please help.</p>