<?php

namespace App\Http\Middleware;

use Closure;
use Auth; //at the top

class Staff
{

    function handle($request, Closure $next, $guard = null)
  {
    if(!empty(Auth::user()->role)){
      if (Auth::check() && Auth::user()->role == 'Staff' || Auth::user()->role == 'Administrator' || Auth::user()->role == 'Leader') {
          return $next($request);
      }
      else {
        return response()->view('errors.403', [], 403);
      }
    }else{
      return redirect()->guest('login');
    }
    Auth::logout($request);
    return $next($request);
    
  }
}