Laravel检查唯一规则而不更新自身 [英] Laravel check for unique rule without itself in update
问题描述
我在更新部分中具有唯一性的验证规则.
I am having my validation rules for unique in the update section.
在插入或添加唯一规则时,是'Email'=>array('unique:driver_details')
,它将检查唯一的列.
In inserting or adding the unique rule is 'Email' => array('unique:driver_details'),
and it will check for the unique coloumn.
但是更新部分失败.更新时,它满足其他规则,并且在电子邮件的唯一性中,它正在检查自己是否具有唯一性,并且失败了,但看到了它自己的字段.
But this fails for the update section. While updating it satisfies the other rules and in the unique of email it is checking itself for the unique coloumn and it fails but seeing its own field.
那么,如何在数据库中检查唯一性值(唯一值除外)?
So, how can i check for the unique except its own value in the database ?
推荐答案
这将强制忽略特定ID:
This forces to ignore specific id:
'email' => 'unique:table,email_column_to_check,id_to_ignore'
在上面的示例中,
替换段表
, email_column_to_check
, id_to_ignore
replace segments table
, email_column_to_check
, id_to_ignore
in above example
您可以在此处进行检查 http://laravel.com/docs/4.2/validation#rule-unique
You could check it here http://laravel.com/docs/4.2/validation#rule-unique
这篇关于Laravel检查唯一规则而不更新自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!