buildadmin/app/admin/validate/Admin.php

73 lines
1.9 KiB
PHP
Raw Normal View History

2022-03-11 17:29:06 +00:00
<?php
namespace app\admin\validate;
use think\Validate;
class Admin extends Validate
{
protected $failException = true;
2022-03-11 17:29:06 +00:00
protected $rule = [
'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:admin',
'nickname' => 'require',
'password' => 'require|regex:^[a-zA-Z0-9_]{6,32}$',
'email' => 'email|unique:admin',
'mobile' => 'mobile|unique:admin',
'group_name_arr' => 'require|array',
2022-03-11 17:29:06 +00:00
];
/**
* 验证提示信息
* @var array
*/
protected $message = [];
/**
* 字段描述
*/
protected $field = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => ['username', 'nickname', 'password', 'email', 'mobile', 'group_name_arr'],
2022-03-11 17:29:06 +00:00
];
/**
* 验证场景-前台自己修改自己资料
*/
public function sceneInfo()
{
return $this->only(['nickname', 'password', 'email', 'mobile'])
->remove('password', 'require');
}
/**
* 验证场景-编辑资料
*/
public function sceneEdit()
{
return $this->only(['username', 'nickname', 'password', 'email', 'mobile', 'group_name_arr'])
->remove('password', 'require');
}
2022-03-11 17:29:06 +00:00
public function __construct()
{
$this->field = [
'username' => __('Username'),
'nickname' => __('Nickname'),
'password' => __('Password'),
'email' => __('Email'),
'mobile' => __('Mobile'),
'group_name_arr' => __('Group Name Arr'),
2022-03-11 17:29:06 +00:00
];
$this->message = array_merge($this->message, [
'username.regex' => __('Please input correct username'),
'password.regex' => __('Please input correct password')
]);
parent::__construct();
}
}