<?php

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{

    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
//           return redirect(RouteServiceProvider::HOME);
            if(\auth()->user()->getRole() === 'manager')
                return redirect()->route('manager.home');
            elseif (\auth()->user()->getRole() === 'rec')
                return  redirect()->route('rec.home');
            elseif (\auth()->user()->getRole() === 'hdc')
                return  redirect()->route('hdc.home');
            elseif (\auth()->user()->getRole() === 'swc')
                return  redirect()->route('swc.home');
            elseif (\auth()->user()->getRole() === 'mob')
                return  redirect()->route('mob.home');
        }

        return $next($request);
    }
}
