Laravel Fortify validation errors not working

Viewed 1297

I'm trying Fortify since one week now and I'm stuck on the same problem at two level.

The problem is when I try to update user password, it doesn't show me validation errors (I mean, when for test purpose I leave fields blank).

The same thing when I try to update user informations (name, email... when I leave them blank for test purpose).

Of course I tried to iterate the $errors variable to display errors message on my views but nothing. I also tried with the @error blade directive but nothing too.

Here's my update password view where I perform an PUT submit to the user-password.update route defined by Fortify

enter image description here

Thanks for your help.

3 Answers

You can use the following code in your blade

@if ($errors->updatePassword->any())
     <ul>
         @foreach($errors->updatePassword->all() as $error)
            <li>{{ $error }}</li>
         @endforeach
     </ul>
@endif

This "$errors->updatePassword" is the Bag Name which will be found in "app/Actions/Fortify/UpdateUserPassword.php"

its work

@if ($errors->updatePassword->any())
 <ul>
     @foreach($errors->updatePassword->all() as $error)
        <li>{{ $error }}</li>
     @endforeach
 </ul>
@endif

or you can change method validateWithBag('updatePassword') in "app/Actions/Fortify/UpdateUserPassword.php" with validate()

Thank you so much, @MNI Noyon

@if( $errors->confirmTwoFactorAuthentication->any() )
<div class="mb-3">
    <ul>
        @foreach( $errors->confirmTwoFactorAuthentication->all() as $error )
            <li class="text-red-500 text-xs" >{{ $error }}</li>
        @endforeach
    </ul>
</div>
@endif

And to @arul project's point, I would have to update vendor/fortify/src/Actions/ConfirmTwoFactorAuthenticate.php from

 ])->errorBag('confirmTwoFactorAuthentication');

to

 ])->validate();

if I wanted to access the errors via $errors->any(). But please correct me if I am wrong.

Related