Laravel 5.3日期验证器:等于或在start_date之后 [英] Laravel 5.3 date validator: equal to or after start_date

查看:220
本文介绍了Laravel 5.3日期验证器:等于或在start_date之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.3验证事件的开始日期和结束日期. end_date应该等于start_date或之后的日期. end_date >= start_date

I'm using Laravel 5.3 to validate start_date and end_date for an event. end_date should be equal to start_date or the after date. end_date >= start_date

$validator = Validator::make($data, [
    'start_date'    => 'required|date',
    'end_date'      => 'required|date|after:start_date',
]);

我尝试在之后使用,但是它仅适用于end_date> start_date. 当然,我可以使用Validator::extend添加自定义规则,但是我想知道是否可以在不添加自定义规则的情况下进行操作.

I tried to use after, but it only works for end_date > start_date. Of course, I can add custom rule using Validator::extend, but I'd like to know if we can do without adding custom rule.

有什么方法可以添加否定规则或添加> =规则?

Is there any way to add negative rule or add >= rule?

谢谢

推荐答案

$validator = Validator::make($data, [
    'start_date'    => 'required|date',
    'end_date'      => 'required|date|after_or_equal:start_date',
]);

使用 after_or_equal

这篇关于Laravel 5.3日期验证器:等于或在start_date之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆