You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\validate;
|
|
|
|
use think\Validate;
|
|
|
|
class Log extends Validate
|
|
{
|
|
/**
|
|
* 定义验证规则
|
|
* 格式:'字段名' => ['规则1','规则2'...]
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $rule = [
|
|
'username|管理员账号' => "length:1,20",
|
|
];
|
|
|
|
/**
|
|
* 定义错误信息
|
|
* 格式:'字段名.规则名' => '错误信息'
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $message = [
|
|
'username.length' => '管理员账号名称必需在1~20位之间',
|
|
];
|
|
|
|
/**
|
|
* 验证场景规则
|
|
* @var array
|
|
*/
|
|
protected $scene = [
|
|
'read' => ['id'],
|
|
];
|
|
|
|
/**
|
|
* 修改场景验证
|
|
* @return Manager
|
|
*/
|
|
public function sceneUpdate()
|
|
{
|
|
return $this->remove('username', 'require')
|
|
->remove('truename', 'require')
|
|
->remove('phone', 'require');
|
|
//需删除以上代码,重新定义
|
|
}
|
|
|
|
/**
|
|
* 自定义查询场景验证 可灵活设置验证字段
|
|
* @return Manager
|
|
*/
|
|
public function sceneLists()
|
|
{
|
|
return $this->only(['username', 'truename', 'sex'])
|
|
->remove('username', 'uniqueSite|require|length')
|
|
->append('username', 'min:1|max:20')
|
|
->remove('truename', 'uniqueSite|require');
|
|
//需删除以上代码,重新定义
|
|
}
|
|
}
|
|
|