-1

帮我解决这个问题

$this->validate($request, [
    'period_starts' => 'required|numeric|digits:4|min:2010|max:'.(date('Y')),
    'period_ends' => 'required|numeric|digits:4|gt:period_starts',
]);

有没有办法验证 period_ends 大于 period_starts 但只有 max +2 不允许更多

4

2 回答 2

0
$this->validate($request, [
    'period_starts' => 'required|numeric|digits:4|min:2010|max:'.(date('Y')),
    'period_ends' => 'required|numeric|digits:4|gt:period_starts|max:'.(($request->period_starts)+2)
]);
于 2021-01-06T04:41:35.890 回答
0

我认为您需要添加 2 两个 gt:period_starts 然后使用 before_or_equal:new period_starts 规则参考

https://laravel.com/docs/8.x/validation#rule-before-or-equal

于 2021-01-05T09:37:17.990 回答