title: how to use session in middleware to always check that a user is logged in or not
body: <p>i am new in laravel . i am trying to check if user is logged in or guest . i create a middleware named (checkUserLogin) and my code is:</p>
  
  <pre><code>namespace App\Http\Middleware;
  use Auth;
  use Closure;
  use App\Http\Controllers\Controller;
  use session;
  class checkUserLogin
  {
      public function handle($request, Closure $next)
  {
      if (session()-&gt;get('email') != ''){
          // redirected to dashboard.
      }else{
          // redirect to login page.
      }
      return $next($request);
     }
    }`
  </code></pre>
  
  <p>in my controller and blade template <code>session()-&gt;get('email')</code> works fine and i get the email of the user who logged in but in middleware if i try to print the <code>session()-&gt;get('email')</code> then a blank screen appears.</p>