I have contacts table with field email and alteranate_email. While adding new contact i want to check email address should not present in either email or alteranate_email. For Example, There is contact present with alteranate_email = '[email protected]'. When I tried to add new contact with email = '[email protected]', it allows me to add new contact.
I have tried below code but its not working.
$validator = Validator::make($request->all(), [
'email' => ['nullable', 'email',
Rule::unique('contacts')->where(function ($query) use ($request) {
return $query->where('email', $request->email)->orWhere('alteranate_email', $request->email);
}),
],
]);
unique:andcontacts-'email' => 'nullable|email|unique:contacts.email,alteranate_email'