By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController :
public function username()
{
return 'phone';
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have been trying to solve this enigma by trying to override the username function but what it does is just reloading and brings me back to the login and saying "These credentials do not match our records", sign up works just fine but on this nothing progressive happen, also i have tried overriding the credentials, also not bearing any fruits, here is my logincontroller
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->username = $this->findUsername();
}
public function findUsername()
{
$login = request()->input('email');
$fieldType = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'phone_number';
request()->merge([$fieldType => $login]);
return $fieldType;
}
}
Please help, i have searched but no where to find the proper answer for this solution.
By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController :
public function username()
{
return 'phone';
}
Please or to participate in this conversation.