validate([ $this->username() => 'required|string', 'password' => 'required|string', ]); } /** * Attempt to log the user into the application. */ protected function attemptLogin(Request $request): bool { return $this->guard()->attempt( $this->credentials($request), $request->boolean('remember') ); } /** * Get the needed authorization credentials from the request. * * @return array */ protected function credentials(Request $request): array { return $request->only($this->username(), 'password'); } /** * Send the response after the user was authenticated. */ protected function sendLoginResponse(Request $request): RedirectResponse|JsonResponse { $request->session()->regenerate(); $this->clearLoginAttempts($request); if ($response = $this->authenticated($request, $this->guard()->user())) { return $response; } return $request->wantsJson() ? new JsonResponse([], 204) : redirect()->intended($this->redirectPath()); } /** * The user has been authenticated. * * @param mixed $user * @return RedirectResponse|JsonResponse|null */ protected function authenticated(Request $request, $user): mixed { return null; } /** * Get the failed login response instance. * * @throws ValidationException */ protected function sendFailedLoginResponse(Request $request): never { throw ValidationException::withMessages([ $this->username() => [trans('auth.failed')], ]); } /** * Get the login username to be used by the controller. */ public function username(): string { return 'email'; } /** * Get the guard to be used during authentication. */ protected function guard(): StatefulGuard { return Auth::guard(); } }