Rule::notIn([]) - is not catching the duplicate entry? is not working for me?
I have a group of people that I don't want to enter the same email address. if a new member joins, they need to enter a unique email address for that group. [$this->familyEmails] holds the email already in the group. It is a one dimensional array. Here is the result of two dd() calls.
And the Rules function (notice that the dd() calls that produced the output in the above graphics is commented out:
public function rules(){
//dd('family emails',$this->familyEmails);
$w = [];
foreach($this->familyEmails as $femail){
if($femail != $this->email && array_search(strtolower($femail),$w)==null)
$w[] = strtolower($femail);
}
// dd(['rules_array'=>$w]);
return [
'email' => ['nullable','string', 'email', 'max:255',Rule::notIn($w)],
];
}
and the Custom Messages function
public function customMessages(){
return [
'email.string' => 'Email Address: The email you entered is not a proper email address; please change.',
'email.email' => 'Email Address: The email you entered is not a proper email address; please change.',
'email.max' => 'Email Address: The email you entered is too long; please change.',
'email.not_in' => 'This email address is already used in the family. Please enter another Email Address',
];
}
I also have an updated() function which validates data entered on the fly
public function updated($propertyName){
$data = $this->validateOnly($propertyName, $this->rules(), $this->customMessages());
$this->resetErrorBag($propertyName);
$this->changesMade = true;
//dd(['data'=>$data,'rules'=>$this->rules()]);
}
After I enter in an email address into the form, the dd() that you see commented out just above produces the following when i enter in an email that is in the notIn rule. The dd() seen just above should not be reached, but it is.

