Borichon's avatar

Request validation didn't give the field in fault

Hi all,

I'm starting a new simplet test project with Laravel 11.

I'm using a request like always :

$validated = $request->validate([
            'nom'       => 'required | max:255',
            'prenom'    => 'required | max:255',
            'email'     => 'required | email | max:255 | unique:users',
            'motdepasse'  => 'required | min:8 | confirmed',
            'profil_id' => 'required | exists:profils,id',
            'actif'     => 'required | integer | between:0,1',
        ]);

And i'm showing the errors like always :

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

But, i'm only get the error type, not the field name in error :

validation.confirmed

I really don't get what i'm doing wrong, it's making me crazy trying to debbug my projet with that :P

Thanks

0 likes
4 replies
Snapey's avatar

did you try @dd($error) to see what you are actually dealing with?

Borichon's avatar

Hi Snapey,

@dd($error) just return that

"validation.required" // resources\views/layouts/myview

even the default validation for register user make return error like that.

I don't know if that matter but :

I only use UUID style for primary key, I have choose fr on localisation config. i use default database session, i have try on file, but no change.

Thanks for your help.

Snapey's avatar
Snapey
Best Answer
Level 122

My guess is that you don't have a french translation for validation.confirmed

in english, validation.confirmed is translated to 'confirmed' => 'The :attribute confirmation does not match.',

If you don't have the translation string then :attribute does not get swapped for motdepasse

Also, change your errors display like;

    @foreach ($errors->all() as $key => $error)
        <li>{{ $key }}: {{ $error }}</li>
    @endforeach
1 like
Borichon's avatar

Hi, thanks for your help

I have published the translation and copy/past the french files from another project. The translation is used, and the problem is gone !!!

0: Le champ nom est obligatoire. 1: Le champ adresse courriel est obligatoire.

Thanks a lot, you save my weeks !!

And now i understand why the resquest class return me an error on my submit... i used the wrong requestClass.... LOL.

Please or to participate in this conversation.