[top-think/think]使用unique:user找不到user表

2023-12-27 518 views
0

`class User extends Validate { protected $rule = [ 'account' => 'alphaNum|require|length:4,11|token|unique:users', 'password' => 'require|min:6', 'password_confirm' => 'require|confirm', 'email' => 'email|unique:user', 'name' => 'chs|require|length:4,8', 'phone' => 'number', ];

protected $message = [
    'account.alphaNum' => '账号只能是字母和数字',
    'account.require'  => '账号不能为空',
    'account.length'   => '账号长度规定为4~11位',
    'account.unique'   => '账号已经存在',
    'password.require' => '密码不能为空',
    'password.confirm' => '两次输入的密码不一致',
    'password.min'     => '密码至少需要6位',
    'email.email'      => '电子邮箱格式不正确',
    'email.unique'     => '电子邮箱已经存在',
    'name.length'      => '姓名最大字数为4',
    'name.chs'         => '姓名只能是中文',
    'phone.number'     => '电话号码只能是数字',
];

protected $scene = [
    'login'  =>  ['account','password'],
];

} 使用唯一验证“unique:user”会找不到user表,但是使用unique:users就不会报错了,不知道是不是Bug SQLSTATE[42S02]: Base table or view not found: 1146 Table 'yqadmin.yq' doesn't exist`

回答

6

你要有user的模型吧.

8

public function loginAction() { $loginInfo = $this->request->post(); $validate = $this->validate($loginInfo,'User.login'); true !== $validate && $this->error($validate); dump($validate); }

我是在控制器里验证的,一定要User模型吗?将表名yq_user修改为yq_users,然后用unique:users就能成功验证了. @momoca

6

@nonme 我看了一下原码.是model和db都是可以,那你可以试试指定一下pk字段吧.文档中有例子.