<?php

namespace App\Http\Middleware;

use Closure;
use Auth; //at the top

class Agencies
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    function handle($request, Closure $next, $guard = null)
	{
		if(!empty(Auth::user()->role)){
			if (Auth::check() && Auth::user()->role == 'Agencies') {
				return $next($request);
			}
			elseif (Auth::check() && Auth::user()->role == 'Agencies') {
				return response()->view('errors.403', [], 403);
			}
			else {
				return response()->view('errors.403', [], 403);
			}
		}else{
			return redirect()->guest('login');
		}
		Auth::logout($request);
		echo "ad";
		exit();
		return $next($request);
		
	}
}
