skip to Main Content

Laravel – 11: How to change default login error message: ‘these credentials do not match our records’

i try to search i cannot found it i need to change this message to another message laravel 11 like username or password is incorrect

2

Answers


  1. you have to over write sendFailedLoginResponse method (this method is in AuthenticatesUsers traits)
    in your loginController with custom message:

    // other login methods
    
        public function sendFailedLoginResponse(Request $request)
        {
            throw ValidationException::withMessages([
                $this->username() => [trans('auth.failed')],
            ]);
        }
    // other login methods
    

    edit this part

                $this->username() => [trans('auth.failed')],
    

    with custom message

    Login or Signup to reply.
  2. The first thing You do is go to LoginRequest

    appHttpRequestsAuthLoginRequest.php

    you will find this function

    
        public function authenticate(): void
    {
        $this->ensureIsNotRateLimited();
    
        if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
            RateLimiter::hit($this->throttleKey());
    
            throw ValidationException::withMessages([
                'email' => trans('auth.failed'),
            ]);
        }
    
        RateLimiter::clear($this->throttleKey());
    }
    
    
    and now change trans('auth.failed') to your customized message
    
    
        public function authenticate(): void
    {
        $this->ensureIsNotRateLimited();
    
        if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
            RateLimiter::hit($this->throttleKey());
    
            throw ValidationException::withMessages([
                'email' => 'Username or password is incorrect',
            ]);
        }
    
        RateLimiter::clear($this->throttleKey());
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search