Skip to content

Instantly share code, notes, and snippets.

@njxqlus
Last active July 24, 2017 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njxqlus/7333115bf2a51916a9af3bbe66c5a639 to your computer and use it in GitHub Desktop.
Save njxqlus/7333115bf2a51916a9af3bbe66c5a639 to your computer and use it in GitHub Desktop.
Laravel Auth by email and username for web and api routes

Laravel Auth by email and username for web and api routes

Instruction

  1. Add code to LoginController.php
  2. Add username column to users table
<?php
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
$field = filter_var($request->get($this->username()), FILTER_VALIDATE_EMAIL)
? $this->username()
: 'username';
return [
$field => $request->get($this->username()),
'password' => $request->password,
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment