It is better to use @error blade directive: https://laravel.com/docs/9.x/validation#the-at-error-directive
Validation messages not showing anymore
Hi there, I didn't change anything special in my project. But for all my form validation cases, the validation messages stopped showing. This for example is my user update validator
$request->validate([
'name' => 'required|max:255',
'email' => 'required|email|unique:users,email,'.$user->id,
'unique_url' => 'required|unique:users,unique_url,'.$user->id,
// 'role' => 'required',
]);
this is how I print all my error messages per field.
@if($errors->has('email'))
<div class="alert alert-danger">
{{ $errors->first('email') }}
</div>
@endif
But when I do this:
@if($errors)
{{ dd($errors->all()) }}
@endif
it returns:
array:1 [▼
0 => "The name field is required."
]
(left the name field empty, to create the error) Does anyone know what the problem is? I see that the error key is 0 rather than name. So that might be the problem. But not sure how to fix this. Cause I didn't have this problem before.
I fixed the issue. There wasn't a problem with my code. It appeared that a JS library it's CSS had also a class .alert on display: none which made my error messages invisible. Maybe next time, use some more precise class names to prevent these kind of issues in the near future.
Please or to participate in this conversation.