Laravel 4 验证唯一(数据库)忽略当前 [英] Laravel 4 Validation unique(database) ignore current

查看:18
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆