<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureUserHasRole
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @param mixed ...$roles
     * @return Response
     */
    public function handle(Request $request, Closure $next, ... $roles): Response
    {
        if(in_array($request->user()->role, $roles)) {
            return $next($request);
        }
        abort(404);
//        return redirect('/home');
    }
}
