<?php

namespace App\Http\Middleware;

use Closure;
use Spatie\Permission\Middleware\RoleMiddleware as SpatieRoleMiddleware;

class RoleMiddleware extends SpatieRoleMiddleware
{
    public function handle($request, Closure $next, $role, $guard = null)
    {
        if (str_contains($request->path(), 'admin')) {
            if ($request->getMethod() != 'GET' && $request->user() && $request->user()->username == 'demo') {
                exit('Sorry, but you are not allowed to make changes in the demo site.');
            }
        }

        return parent::handle($request, $next, $role, $guard);
    }
}
