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

[8.x] Silence Validator Date Parse Warnings #38652

Merged

Conversation

tomirons
Copy link
Contributor

@tomirons tomirons commented Sep 2, 2021

Using any date comparison validation rule and having the first parameter be another attribute name will generate PHP warnings. In our case, tons of them and from different endpoints. 😱

Problem Code:

<?php
$validator = \Illuminate\Support\Facades\Validator::make([
    'start_date' => '2021-01-01',
    'end_date' => '2021-01-02',
], [
    'start_date' => ['required', 'date_format:Y-m-d', 'before_or_equal:end_date'],
    'end_date'   => ['required', 'date_format:Y-m-d', 'after_or_equal:start_date'],
]);

$validator->validate();

image

@tomirons tomirons force-pushed the validator-date-comparison-warning branch from 33557af to ce1705a Compare September 2, 2021 19:43
@GrahamCampbell
Copy link
Member

Double parsing is gonna slow things down 2x. Better to just silence the error and check if the output is false/null or whatever it does when there's an error?

@tomirons tomirons force-pushed the validator-date-comparison-warning branch from ce1705a to bdcb303 Compare September 2, 2021 19:57
@tomirons tomirons force-pushed the validator-date-comparison-warning branch from bdcb303 to af59a73 Compare September 2, 2021 20:00
@tomirons tomirons changed the title [8.x] Ensure validator attribute is a valid date [8.x] Silence Validator Date Parse Warnings Sep 3, 2021
@taylorotwell taylorotwell merged commit 0ea3bb6 into laravel:8.x Sep 3, 2021
@tomirons tomirons deleted the validator-date-comparison-warning branch September 3, 2021 15:40
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
chu121su12 pushed a commit to chu121su12/framework that referenced this pull request Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants