Laravel 4验证唯一(数据库)忽略当前 [英] Laravel 4 Validation unique(database) ignore current
本文介绍了Laravel 4验证唯一(数据库)忽略当前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在对用户编辑表单进行验证,并进行验证检查用户名在数据库中是否唯一.
I'm doing validation on a users edit form and have the validation checking if the username is unique in the database or not.
但是,当编辑用户并且您不更改用户名字段时,它仍在检查该字段是否唯一...
However when the editing a user and you don't change the username field it's still checking if the field is unique or not...
是否有laravel方式可以忽略当前用户名(如果未更改)?
Is there a laravel way to ignore the current username if not changed?
推荐答案
应该多读一些文档,当然laravel 4会这样做...
Should have read the docs more, of course laravel 4 does this...
$rules = array('username' => 'required|unique:users');
我有什么
$rules = array('username' => 'required|unique:users,username,'.$id);
您可以告诉验证者忽略上述给定的ID.
You can tell the validator to ignore a given ID like above.
这篇关于Laravel 4验证唯一(数据库)忽略当前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文