Skip to content

Instantly share code, notes, and snippets.

@Ademking
Last active July 20, 2018 03:14
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 Ademking/6cfac0b38bc2a9eaf333336e9be129c9 to your computer and use it in GitHub Desktop.
Save Ademking/6cfac0b38bc2a9eaf333336e9be129c9 to your computer and use it in GitHub Desktop.
❤️ Laravel : (5.5) : Allow login using username or email
// in app/Http/Controllers/Auth/LoginController.php
<?php
/*
* code ...
*/
use AuthenticatesUsers;
protected function credentials(Request $request)
{
$login = request()->input('email');
// Check whether username or email is being used
$field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
return [
$field => $request->get('email'),
'password' => $request->password
];
}
/*
* code ...
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment