From 10150d7f138c21bcd89e63871b4c7e6e2361cbce Mon Sep 17 00:00:00 2001 From: Karson Date: Wed, 7 Jan 2026 18:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/auth/Rule.php | 9 +++++---- application/admin/validate/AuthRule.php | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/application/admin/controller/auth/Rule.php b/application/admin/controller/auth/Rule.php index 63aca234..1ea043eb 100644 --- a/application/admin/controller/auth/Rule.php +++ b/application/admin/controller/auth/Rule.php @@ -99,7 +99,8 @@ class Rule extends Backend if (!$params['ismenu'] && !$params['pid']) { $this->error(__('The non-menu rule must have parent')); } - $result = $this->model->validate()->save($params); + $validate = \think\Loader::validate('AuthRule', 'validate', false, 'admin'); + $result = $this->model->validate($validate)->save($params); if ($result === false) { $this->error($this->model->getError()); } @@ -137,11 +138,11 @@ class Rule extends Backend } } //这里需要针对name做唯一验证 - $ruleValidate = \think\Loader::validate('AuthRule'); + $ruleValidate = \think\Loader::validate('AuthRule', 'validate', false, 'admin'); $ruleValidate->rule([ - 'name' => 'require|unique:AuthRule,name,' . $row->id, + 'name' => 'require|regex:format|unique:AuthRule,name,' . $row->id, ]); - $result = $row->validate()->save($params); + $result = $row->validate($ruleValidate)->save($params); if ($result === false) { $this->error($row->getError()); } diff --git a/application/admin/validate/AuthRule.php b/application/admin/validate/AuthRule.php index 3919ea0c..ddccef60 100644 --- a/application/admin/validate/AuthRule.php +++ b/application/admin/validate/AuthRule.php @@ -16,7 +16,7 @@ class AuthRule extends Validate * 验证规则 */ protected $rule = [ - 'name' => 'require|unique:AuthRule', + 'name' => 'require|regex:format|unique:AuthRule', 'title' => 'require', ]; @@ -24,7 +24,7 @@ class AuthRule extends Validate * 提示消息 */ protected $message = [ - 'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成' + 'name.regex' => 'URL规则只能是小写字母、数字、下划线和/组成' ]; /** @@ -45,7 +45,7 @@ class AuthRule extends Validate 'name' => __('Name'), 'title' => __('Title'), ]; - $this->message['name.format'] = __('Name only supports letters, numbers, underscore and slash'); + $this->message['name.regex'] = __('Name only supports letters, numbers, underscore and slash'); parent::__construct($rules, $message, $field); }