Laravel Framework

Laravel 5.3 login with username instead of email

Laravel’s built in auth system uses an email address and password to validate credentials for cases where you want to use a username instead of an email address you can do the following:

Add a username column to the users table then add a username() method to App/Controllers/Auth/LoginController:

the default is email so place ‘username’ instead and this will be used instead of an email.

public function username()
{
    return 'username';
}

Next edit the login view and change the email field to a username field.

That’s it.

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.