modify laravel 5.1 login to use username instead of email

5.8k Views Asked by At

This function is responsible of defining the username in laravel 5.1 authentication:

public function loginUsername()
{
    return property_exists($this, 'username') ? $this->username : 'email';
}

if I modify it to

public function loginUsername()
    {
        return property_exists($this, 'username') ? $this->username : 'username';
    }

in the foundation file (and adapt my views and db) will this persist in the event of an update? and if not how do I override it and leave the foundation file alone? I already made a new controller for registering user and I am calling it in my route instead of the default one, however I am finding difficult to do the same with the postlogin route.

1

There are 1 best solutions below

5
Jim M On BEST ANSWER

Instead of modifying that in AuthenticatesUsers trait, you just have to add a property on your AuthController:

protected $username = 'username';