Laravel 4-如何验证多个字段的唯一性? [英] Laravel 4 - How to validate unique with multiple fields?
本文介绍了Laravel 4-如何验证多个字段的唯一性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的架构:
Schema::create('members', function(Blueprint $table)
{
$table->increments('id');
$table->string('lname');
$table->string('fname');
$table->integer('mname');
$table->unique(array('lname', 'fname'));
});
我的问题是,如何验证这些唯一字段?
My problem is, how to validate these unique fields?
我尝试过,但是我知道这是错误的...
I tried this but I know this is wrong...
public static $rules = array(
'lname' => 'unique:members',
'fname' => 'unique:members'
);
感谢您的帮助..:)
推荐答案
您应使用此软件包 https://github.com/felixkiss/uniquewith-validator
像这样使用它:
$rules = array(
'<field1>' => 'unique_with:<table>,<field2>[,<field3>,...,<ignore_rowid>]',
);
这篇关于Laravel 4-如何验证多个字段的唯一性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文