Reputation:
In the validation.php file the error message is like this:
'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
However when this error occurs the message that appears is :
validation.after_or_equal
Do you know why?
Code to show the messages in the view:
@if ($errors->any())
<div class="alert alert-danger mt-3">
<ul>
@foreach ($errors->all() as $error)
<li class="text-danger">{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Store method with validation:
public function store(Request $request)
{
$this->validate($request, [
'startDate' => 'required|date_format:d F Y - H:i',
'endDate' => 'required|date_format:d F Y - H:i|after_or_equal:startDate',
]);
}
View that includes the errors file:
@extends('layouts')
@section('content')
<div class="container-fluid px-4">
@include('includes.errors')
<form id="edit_admins" method="post" class="clearfix"
action="{{route('admins.update', ['post_id' => $post->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
....
</form>
@endsection
Upvotes: 1
Views: 582
Reputation: 86
So confirm where did you put your code 'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
, because if you put in wring place you will receive this message validation.after_or_equal
.
You need to put in this place on validation.php:
<?php
return [
/*
|------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
| the validator class. Some of these rules have multiple versions such
| as the size rules. Feel free to tweak each of these messages here.
|
*/
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.',
'after_or_equal' => 'A :attribute must be a date after or equal to :date.',
...
If the things okay, check your app locale, maybe you're in another language.
Upvotes: 1
Reputation: 333
The issue seems to be that the date_format
validation rule should have the date format surrounded by "
.
Here is the updated snippet.
public function store(Request $request)
{
$this->validate($request, [
'startDate' => 'required|date_format:"d F Y - H:i"',
'endDate' => 'required|date_format:"d F Y - H:i"|after_or_equal:startDate',
]);
}
Upvotes: 0