I have a registration form with unique email validation, when i enter multiple duplicate emails it does not apply unique validation for email i have rules below, Note: i am using mongodb.
public static $rules = array(
'email' => 'required|email|unique:users'
);
I added a validation test in https://github.com/jenssegers/Laravel-MongoDB/blob/master/tests/ValidationTest.php and it seems to work.
In case someone runs into this again, the likely culprit is if you're using multiple database connections and MongoDB is not your default. In this case, you must set the presence verifier's connection to your MongoDB connection key prior to validating, then all should work well.
One way to do it is in the authorize() method of a custom FormRequest class (because it is called prior to validate()). Example:
public function authorize(){
// Make MongoDB the presence verifier
$this->getValidatorInstance()->getPresenceVerifier()->setConnection('mongodb');
// in this case we're authorizing any user
return true;
}
In case someone runs into this again, the likely culprit is if you're using multiple database connections and MongoDB is not your default. In this case, you must set the presence verifier's connection to your MongoDB connection key prior to validating, then all should work well.
One way to do it is in the authorize() method of a custom FormRequest class (because it is called prior to validate()). Example:
public function authorize(){ // Make MongoDB the presence verifier $this->getValidatorInstance()->getPresenceVerifier()->setConnection('mongodb'); // in this case we're authorizing any user return true; }
Other solution is to specify the database connection in unique validation
'email' => 'unique:mongodb.users,email_address'
Most helpful comment
Other solution is to specify the database connection in unique validation
'email' => 'unique:mongodb.users,email_address'