<?php
/**
 * ${CARET}
 * @file:${FILE_NAME}
 * @Created by gnitif
 * @Date: 2023/5/6
 * @Time: 16:38
 */


namespace Modules\CpManage\Middlewares;

use Illuminate\Http\Request;
use Modules\Permissions\Exceptions\PermissionForbidden;
use Modules\User\Models\User;

class CpManageGate
{
    public function handle(Request $request, \Closure $next)
    {
        if ($request->isMethod('get')) {
            return $next($request);
        }

        /* @var User $user */
        $user = $request->user(getGuardName());

        if (! $user->can()) {
            throw new PermissionForbidden();
        }

        return $next($request);
    }
}
