如何在Laravel中验证正在更新用户的唯一电子邮件? [英] How validate unique email out of the user that is updating it in Laravel?
本文介绍了如何在Laravel中验证正在更新用户的唯一电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 5.2,并想使用验证器更新用户帐户.
I am using Laravel 5.2 and want to update user's account using validator.
我想保持电子邮件字段的唯一性,但是,如果用户键入他当前的电子邮件,它将中断.除了用户自己的当前电子邮件以外,如果电子邮件是唯一的,我该如何更新?
I want to keep email field unique, but, if the user type his current email it will break. How can I update if the email is unique, except the user's own current email?
推荐答案
您可以告诉验证者:
'email' => 'unique:users,email_address,'.$user->id
在强制使用唯一规则忽略A"部分中,检查 docs .给定ID'.
Check the docs, in section 'Forcing A Unique Rule To Ignore A Given ID'.
这篇关于如何在Laravel中验证正在更新用户的唯一电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文