我有一个数据库用户。它有一个电子邮件字段。
我有两个输入字段,名称为users [email]和manager.email。我希望唯一性的验证在用户表上。这是我尝试过的。
<div class="row">
<div class="form-group col-md-12">
<div class="col-md-8">{{ Form::input('text', 'users[email]', '', ['class' => "form-control", 'maxlength' => 255, 'id' => "userEmail", 'placeholder' => "Email Address"]) }}</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<div class="col-md-8">{{ Form::input('text', 'manager[email]', '', ['class' => "form-control", 'maxlength' => 255, 'id' => "email", 'placeholder' => "Manager Email Address"]) }}</div>
</div>
</div>
我的验证器如下:
$validationRules = ['users.email' => 'email|required|unique:users',
'manager.email' => 'email|required|unique:users',
];
因此,当我在验证器中它返回一条消息说明:
Unknown column 'manager.email' in 'where clause' (SQL: select count(*) as aggregate from `users` where `manager`.`email` = 'xyz@email.com')
请引导我完成此操作或建议我更好的方法来解决此问题。
答案 0 :(得分:2)
我想你的问题是因为你没有在你的唯一规则中指定列名。
https://laravel.com/docs/5.2/validation#rule-unique(请参阅指定自定义列名)
尝试更改:
'manager.email' => 'email|required|unique:users'
为:
'manager.email' => 'email|required|unique:users,email'
希望这有帮助!