开源项目

tp5 唯一性验证 踩坑

2018-05-07  本文已影响13人  铁匠简记

validate/Admin.php

<?php
namespace app\admin\validate;
use think\Validate;
/**
 * Description of Validate
 *
 * @author Ivan
 */
class Admin  extends Validate
{
    protected $rule =   [
        'username'  => 'require|min:3|unique:admin',
        'password'   => 'require|min:6',    
    ];
    
    protected $message  =   [
        'username.require' => '用户名必须',
        'username.min'     => '用户名不少于3个字符长度',
        'username.unique'     => '用户名唯一',
        'password.require'   => '用户密码必须',
        'password.min'  => '密码长度必须大于6',
    ];
    
    protected $scene = [
        'add'  =>  ['username','password'],
        'edit' =>  ['username'=>'require|min:3','password'=>'min:6'],
    ];
}

unique后边必须跟上 :表名

上一篇下一篇

猜你喜欢

热点阅读