laravellaravel-8laravel-9laravel-fortify

Laravel: how to customize login error messages through Fortify


I have the following blade view where I want the error messages printed to me:

<x-layout>
    
@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

<section class="colorbody vh-100">
    <div class="container py-5 h-100">
        <div class="row d-flex justify-content-center align-items-center h-100">
            <div class="col-12 col-md-8 col-lg-6 col-xl-5">
                <div class="card shadow-2-strong bordercard">
                    <div class="card-body p-5 text-center">

                        <form method="POST" action="{{route('login')}}">
                            @csrf
                            
                            <div class="d-flex align-items-center mb-3 pb-1">
                            <i class="fa-brands fa-slack fa-2xl me-3"></i>
                            <span class="h1 fw-bold mb-0">Logo</span>
                            </div>

                            <h5 class="fw-normal mb-3 pb-3 letterspace">Enter in your account</h5>

                            <div class="form-outline mb-4">
                            <input type="email" class="form-control form-control-lg" name="email" value="{{ old('email') }}"/>
                            <label class="form-label" for="form2Example17">Email address</label>
                            </div>

                            <div class="form-outline mb-4">
                            <input type="password" class="form-control form-control-lg" name="password"/>
                            <label class="form-label" for="form2Example27">Password</label>
                            </div>

                            <div class="pt-1 mb-4">
                            <button class="btn btn-dark btn-lg btn-block" type="submit">Login</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
</x-layout>

Except that if I insert an invalid email and a password, only the error message (automatically obtained from auth.failed) of the following type is displayed:

These credentials do not match our records.

I would like, for example, to have the following error message:

'The email entered is incorrect'

'The password entered is incorrect'

How can I do this? Can anyone kindly help me?


Solution

  • Edit Authentication Language Lines in resources/lang/en/auth.php

    return [
        'failed' => 'These credentials do not match our records.',
        'password' => 'The provided password is incorrect.',
        'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
    ];