Created
September 25, 2017 17:08
-
-
Save marcoskubis/1b5172422714bb55280c1c069c3f1dc4 to your computer and use it in GitHub Desktop.
Allow login using username or email in Laravel 5.4
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 | |
namespace App\Http\Controllers\Auth; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
class AuthController extends Controller | |
{ | |
use AuthenticatesUsers; | |
/** | |
* Get the login username to be used by the controller. | |
* | |
* @return string | |
*/ | |
public function username() | |
{ | |
if (filter_var(request('username'), FILTER_VALIDATE_EMAIL)) { | |
request()->request->add(['email' => request('username')]); | |
return 'email'; | |
} | |
return 'username'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment