Answers for "How does laravel validate email and password?"

PHP
0

username or email validation in laravel

$input = $request->only('account'); // dont use all(), ever
            
$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);
Posted by: Guest on April-27-2020

Code answers related to "How does laravel validate email and password?"

Browse Popular Code Answers by Language