Laravel 7 login error message not showing

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.

Answers 2
  • 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
    
    0
  • 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.',
    ]);
    
    0
  • Back to code snippet queries related laravel

Related queries helps you to understand and may also used for implementation of current code snippet