<?php

namespace App\Http\Middleware;

use Closure;

class RoleCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $role)
    {
      if($request->user()) {
        if($request->user()->role_id == $role OR $request->user()->role_id >= 6) {
          return $next($request);
        }
      } else {
         return redirect('home');
      }
    }
}
