Laravel: Auth Login with username instead of email
Laravel provides a flexible authentication system out-of-box.
By default, the authentication system uses email for authentication. But it can be easily changed to any other fields like username or phone number.
To change the default authentication you will need to do the following:
- In the login controller define a username function (Controller/Auth/LoginController.php)
1234public function username(){return 'username'; //or return the field which you want to use.} - Edit the login and registration views to change the email field to required authentication field.
- Add the authentication field in the database, by editing create_users_table migration or creating a new migration.
That’s all you need to change and you’re ready.
Small Tip but helpfull.
No Comments