为角色添加路由权限,只存入最后一条数据
你是只删除了最后一条,前面的都是没删除
正确的添加方式
try { $roleId = 2022; $resources = []; $casbinRule = []; foreach ($resources as $resource) { array_push($casbinRule, ['role:'.$roleId, $resource['path'], 'POST']); Permission::deletePermissionsForUser('role:'.$roleId, $resource['path']); } Permission::addPolicies($casbinRule); } catch (\Exception $exception) { throw new ServerErrorHttpException($exception->getMessage()); }
正确的添加方式