Last active
March 8, 2019 09:40
-
-
Save DavidMRGaona/537f03f3d09217c292c0d6e0230bca58 to your computer and use it in GitHub Desktop.
Function that allows the user to log in with both the username and the email.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LoginController extends Controller | |
{ | |
(...) | |
/** | |
* Checks if the parameter passed at login is a username or an email account. | |
* Depending on the check it will return one login method or another | |
* | |
* @override | |
* @return string | |
*/ | |
public function username() | |
{ | |
$loginType = request()->input('username'); | |
$this->username = filter_var($loginType, FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; | |
request()->merge([$this->username => $loginType]); | |
return property_exists($this, 'username') ? $this->username : 'email'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment