I have two date fields in a form: fechaInicial
and fechaFinal
. I have defined them as type date
.
In the controller that receives the form I have put, among other validation rules, the following:
'fechaFinal' => 'required|gte:fechaInicial',
Validation is supposed to fail if the fechaFinal
is before the fechaInicial
. However, it does not fail. Validation passes.
Does gte
n't it work with dates? If so, how should I validate that the end is not before the start? Thanks.
The gte validation rule is not for dates, for that you must use
after_or_equal
, which is exclusive for dates.In your case it would be something like this:
More information at: https://laravel.com/docs/5.7/validation#rule-after-or-equal
I leave a second alternative, it can be useful if you want to perform more complex or personalized verifications. What you can do in this case is to make use of Closures , you can even customize the message to show according to the error.
The code could be something like this: