<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RoleMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next, $permission)
    {

        if (!$request->user()->can($permission)) {
            if ($request->user()->hasRole('admin')) {
            } else {
                abort(404);
            }
        }
        return $next($request);


        // if ($role != null && ) {
        //     abort(404);
        // }
        // if ($permission != null && !$request->user()->can($permission)) {
        //     abort(404);
        // }
    }
}
