My registration form and login form are on the same page, but in different tabs. By default the active tab is login. While registering if there is any errors, the error messages are returned and I can print the error message at the right place by using named error bag.
The problem is when the error is from the registration form, the active tab should be register. For this I need to check the named of laravel validation.
How can I do that??
COde for validation is:
if ($validator->fails()) {
return back()
->withErrors($validator, 'register')
->withInput();
}
Instead, Laravel generates a JSON response containing all of the validation errors. This JSON response will be sent with a 422 HTTP status code. You may use the @error Blade directive to quickly determine if validation error messages exist for a given attribute.
If you are using named error bags, you may pass the name of the error bag as the second argument to the @error directive: When Laravel generates a redirect response due to a validation error, the framework will automatically flash all of the request's input to the session.
Many of Laravel's built-in error messages include an :attribute placeholder that is replaced with the name of the field or attribute under validation.
The field under validation must be numeric. The field under validation must match the authenticated user's password. This rule was renamed to current_password with the intention of removing it in Laravel 9. Please use the Current Password rule instead.
You could try using the ->hasBag()
method on the $errors
variable to check if a bag exists for the given key, which would allow you to output the relevant CSS class or whatever you need to display the correct tab. For example:
<div class="tab registration{!! $errors->hasBag('register') ? ' active' : '' !!}">
</div>
hasBag('register')
will return true
if there's an error bag present for the registration form, assuming you've set up your validation to define which bag to use for registration errors. That will allow you to select the correct tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With