Laravel 7 login error message not showing

Created at 07-Aug-2021 , By samar

Laravel 7 login error message not showing

Hello everyone, in this post we will examine how to solve the "Laravel 7 login error message not showing" programming puzzle.

Laravel 7 login error message not showing in blade file. You can display validation or custom error messages by using the @error directive in laravel. To display the custom error message you have to return back with the custom message using withErrors() method.
  • Display validation error messages for login functionality in laravel

    --PATH resources\views\auth\login.blade.php
    // For email required and invalid login credentials
    @error('email')
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    @enderror
    
    
    //For password required
    @error('password')
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    @enderror
    
  • Return with custom error message other than validation in laravel on login

    --PATH app\Http\Controllers\Auth\LoginController.php
    //Return with validation error message if input is empty
    $credentials = $request->validate([
        'email' => ['required', 'email'],
        'password' => ['required'],
    ]);
    
    //It will redirect to dashboard if everything is ok
    if (Auth::attempt($credentials)) {
        $request->session()->regenerate();
        return redirect()->intended('dashboard');
    }
    
    //Return back to login page with custom error message
    return back()->withErrors([
        'email' => 'The provided credentials do not match our records.',
    ]);
    

Related Queries

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.