Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in rule "after" date validation #49988

Closed
dbfun opened this issue Feb 6, 2024 · 3 comments
Closed

Error in rule "after" date validation #49988

dbfun opened this issue Feb 6, 2024 · 3 comments
Labels

Comments

@dbfun
Copy link

dbfun commented Feb 6, 2024

Laravel Version

10.43.0

PHP Version

8.1.0

Database Driver & Version

No response

Description

This PR breaks the validation of the field if another field plus a temporal offset is specified.

Steps To Reproduce

<?php

require_once(__DIR__ . '/vendor/autoload.php');
$app = require __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

use Illuminate\Support\Facades\Validator;

$data = [
    'dt1' => '2020-01-01',
    'dt2' => '2024-01-01',
];

$val = Validator::make($data, [
    'dt1' => 'required|date',
    'dt2' => 'required|date|after:dt1 +1 day',
]);

/**
 * It works in Laravel 10.42.0
 * And throw exception "The dt2 field must be a date after dt1+1 day." in Laravel 10.43.0
 */
$val->validate();

Details:

Illuminate\Validation\ValidationException 

The dt2 field must be a date after dt1+1 day.

at vendor/laravel/framework/src/Illuminate/Support/helpers.php:330
  326▕     function throw_if($condition, $exception = 'RuntimeException', ...$parameters)
  327▕     {
  328▕         if ($condition) {
  329▕             if (is_string($exception) && class_exists($exception)) {
➜ 330▕                 $exception = new $exception(...$parameters);
  331▕             }
  332▕ 
  333▕             throw is_string($exception) ? new RuntimeException($exception) : $exception;
  334▕         }
@mateusjunges
Copy link
Contributor

#49955

@dbfun
Copy link
Author

dbfun commented Feb 6, 2024

#49955

Thank you, I've seen that issue. It's related, but not quite the same.

@driesvints
Copy link
Member

We've reverted the original PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants