Laravel 4で2つの列の一意性を検証するにはどうすればよいですか?
と が 2 つの列であるfirst_nameとしlast_nameます。first_name last_nameユニークであることを確認したい。
そのためのコミュニティ開発パッケージがあります: https://github.com/felixkiss/uniquewith-validator。
"felixkiss/uniquewith-validator": "dev-master"で、require プロパティに次を追加します。'Felixkiss\UniqueWithValidator\UniqueWithValidatorServiceProvider'最後に、次のように使用します。
$rules = array(
'first_name' => 'unique_with:users,last_name',
);
パッケージページを確認してください。
カスタム Validatior を書くことができます。
http://laravel.com/docs/validation#custom-validation-rules
Validator::extend('foo', function($attribute, $value, $parameters)
{
/*
check whether "first_name + last_name" is unique with SQL. Pass them as parameters
*/
});