// +---------------------------------------------------------------------- declare (strict_types = 1); namespace addon\wxchat\validate; use think\Validate; /** * Member 类 * * @author ywxapp */ class Member extends Validate { // 创建用户验证规则 protected $rule = [ 'temp_token' => 'require', 'nickname' => 'require|max:20', 'gender' => 'in:0,1,2', // 0:未知 1:男 2:女 'birthday' => 'date', 'invite_code' => 'max:20', 'avatar' => 'max:500', ]; // 创建用户验证消息 protected $message = [ 'temp_token.require' => '临时令牌不能为空', 'nickname.require' => '昵称不能为空', 'nickname.max' => '昵称最多20个字符', 'gender.in' => '性别参数错误', 'birthday.date' => '生日格式错误', 'invite_code.max' => '邀请码最多20个字符', 'avatar.max' => '头像地址过长', ]; // 创建用户场景 public function sceneCreate() { return $this->only(['temp_token', 'nickname', 'gender', 'birthday', 'invite_code', 'avatar']) ->remove('nickname', 'require'); // 允许昵称为空,会自动生成 } }