首页 > 解决方案 > 我想在 laravel 中使用用户名或电子邮件更新登录

问题描述

我已将 laravel 默认make:Auth更新为使用用户名和电子邮件登录。我只是有覆盖用户名功能

loginController.php到:

public function username()
    {
        $loginType = request()->input('username');
        $this->username = filter_var($loginType , FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
        request()->merge([$this->username => $loginType]);
        $this->property_exists($this, 'username') ? $this->username : 'email';
    }

但出现错误:

Method [property_exists] does not exist on [App\Http\Controllers\Auth\LoginController].

标签: phplaravel

解决方案


property_exists是一个 php 函数,而不是某个类的方法。所以,要改善这个错误,只需重写你的代码:

public function username()
{
    $loginType = request()->input('username');
    $this->username = filter_var($loginType , FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
    request()->merge([$this->username => $loginType]);
    property_exists($this, 'username') ? $this->username : 'email';
}

推荐阅读