public function username()
{
$login = request()->input('username');
if(is_numeric($login)){
$field = 'phone';
} elseif (filter_var($login, FILTER_VALIDATE_EMAIL)) {
$field = 'email';
} else {
$field = 'username';
}
return $field;
}
<?php
namespace AppHttpControllersAuth;
use AppHttpControllersController;
use AppProvidersRouteServiceProvider;
use IlluminateFoundationAuthAuthenticatesUsers;
use IlluminateHttpRequest;
use IlluminateValidationValidationException;
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');
}
/**
* Get the failed login response instance.
*
* @param IlluminateHttpRequest $request
* @return SymfonyComponentHttpFoundationResponse
*
* @throws IlluminateValidationValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
'username' => [trans('auth.failed')],
]);
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
$login = request()->input('username');
if(is_numeric($login)){
$field = 'phone';
} elseif (filter_var($login, FILTER_VALIDATE_EMAIL)) {
$field = 'email';
} else {
$field = 'username';
}
request()->merge([$field => $login]);
return $field;
}
}