laravel 多字段登录
protected function validateChinaPhoneNumber($number)
{
return preg_match('/^1[34578]\d{9}$/', $number);
}
public function username()
{
$username = request()->get('username');
$map = [
'email' => filter_var($username, FILTER_VALIDATE_EMAIL),
'phone' => $this->validateChinaPhoneNumber($username),
];
$field=key(array_filter($map)) ?? 'username';
request()->merge([$field => $username]);
return $field;
}