Skip to content

Instantly share code, notes, and snippets.

@marcoskubis
Created September 25, 2017 17:08
Show Gist options
  • Save marcoskubis/1b5172422714bb55280c1c069c3f1dc4 to your computer and use it in GitHub Desktop.
Save marcoskubis/1b5172422714bb55280c1c069c3f1dc4 to your computer and use it in GitHub Desktop.
Allow login using username or email in Laravel 5.4
<?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