Validation Errors Not Showing in Blade Template Hello everyone,
I'm facing an issue where validation errors are not displaying in my Blade template. Below is my code:
login.blade.php
<div class="form-group">
<div class="input-group input-group-merge">
<div class="input-icon">
<span class="ti-mobile"></span>
</div>
<input type="tel" name="phone" class="form-control" required placeholder="Enter Your Phone Number">
</div>
</div>
@error('phone')
<p class="text-danger"><small>{{ $message }}</small></p>
@enderror
LoginController.php
$request->validate([
'phone' => 'string|required|exists:api_users,phone',
'password' => 'string|required|min:8'
], [
'phone.exists' => 'This phone number doesn\'t match our records',
]);
The validation should trigger an error message when an invalid phone number is entered, but the message is not showing in the Blade view.
I would appreciate any guidance on what might be causing this issue. Thank you!
@lucius123 Can you check whether you get a validation error if fails?
// Your validation
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
Also, make sure you are using the POST method in the form with the @csrf token.
@tisuchi Thanks for your answer, Sir. I found the issue— I had placed the login function inside the auth-user middleware, which made it work only for authenticated users and not for unauthenticated ones.
Please sign in or create an account to participate in this conversation.