Skip to content

Instantly share code, notes, and snippets.

@DavidMRGaona
Last active March 8, 2019 09:40
Show Gist options
  • Save DavidMRGaona/537f03f3d09217c292c0d6e0230bca58 to your computer and use it in GitHub Desktop.
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.
<?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