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;
    }
 
posted @ 2018-11-21 10:36  花泪哲  阅读(508)  评论(0编辑  收藏  举报