laravel validation edit email code example
Example 1: email validation in laravel
$validator = Validator::make($request->all(), []);
$validator->sometimes('email', 'unique:users,email', function ($input) {
return $input->email !== Auth::user()->email;
});
Example 2: username or email validation in laravel
$input = $request->only('account');
$rules = [
'account' => 'required'
];
if (filter_var($input['account'], FILTER_VALIDATE_EMAIL)) {
$rules['account'] .= '|exists:users,email';
} else {
$rules['account'] .= '|exists:users,username';
}
$messages = [
'account.required' => 'Enter username or email to login.',
];
$validator = Validator::make($input, $rules, $messages);