问题
I have this schema:
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'
);
Any help is appreciated.. :)
回答1:
You should use this package https://github.com/felixkiss/uniquewith-validator
use it like this:
$rules = array(
'<field1>' => 'unique_with:<table>,<field2>[,<field3>,...,<ignore_rowid>]',
);
回答2:
Try the following:
public static $rules = array(
'lname' => 'unique:members,lname',
'fname' => 'unique:members,fname'
);
'lname' => 'unique:members,lname',
^^^^^ "lname" is a column of members table
More info:
http://laravel.com/docs/validation#rule-unique
来源:https://stackoverflow.com/questions/20674620/laravel-4-how-to-validate-unique-with-multiple-fields