<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;


class RandDRedirectMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        
        // if (Auth::check()){
        //     $user = Auth::user();

        //     // if ($user->isRandDMember() && !preg_match('/^RandD(.*)/m', Route::current()->uri)) {
        //     //     return redirect('RandD');
        //     // }

        //     // if($user->permissions()->where('type','randd')->get()->count() == 0 && preg_match('/^RandD(.*)/m', Route::current()->uri)){

        //     //     // dd(Route::current()->uri);
        //     //     return abort(403);
        //     // }

        //     if ($user->hasRole('auditor')) {
        //         return redirect('/cmms-audit');
        //     }
        // } 

        // if (Auth::check() && Auth::user()->hasRole('RandD')) {
        //     return redirect('/RandD');
        // }
        // if (Auth::check() && Auth::user()->hasRole('auditor')) {
        //     return redirect('/cmms-audit');
        // }
        return $next($request);

    }
}
