[英]Validation form unique Laravel 5.4 doesn't work
I have this simple code: 我有这个简单的代码:
$this->validate($request, [
'email' => 'required|email|unique:subscriptions'
]);
However I can keep putting in the same email and it doesn't send me back and error and keeps creating the row in the database. 但是,我可以继续输入相同的电子邮件,并且不会向我发送错误和回信,并且会继续在数据库中创建行。
However if I change the code to .. 但是,如果我将代码更改为..
$this->validate($request, [
'email' => 'required|email|unique:users'
]);
It sends me back an error properly and displays in the div I have setup for it. 它会正确地向我发送错误,并在我为此设置的div中显示。
I have tried many different ways to fix this, but I feel like it should be easier than this. 我尝试了许多不同的方法来解决此问题,但是我觉得它应该比这容易。 I looked at everything and it doesn't seem to address this issue.
我查看了所有内容,但似乎无法解决此问题。 Any help would be great.
任何帮助都会很棒。
You need to specify the column name 您需要指定列名
$this->validate($request, [
'email' => 'required|email|unique:subscriptions,email'
]);
$this->validate($request, [
'email' => 'required|email|unique:users,email'
]);
While updating you need to force a unique rule to Ignore Given ID 更新时,您需要强制使用唯一规则来忽略给定ID
'email' => 'unique:subscriptions,email,'.$user->id
https://laravel.com/docs/5.2/validation#rule-unique https://laravel.com/docs/5.2/validation#rule-unique
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.