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

[5.2] Validation of dates - Dealing with DateTime instances #13844

Merged
merged 2 commits into from
Jun 3, 2016
Merged

[5.2] Validation of dates - Dealing with DateTime instances #13844

merged 2 commits into from
Jun 3, 2016

Conversation

KennedyTedesco
Copy link
Contributor

This PR allows to pass DateTime instances when validating using After and Before.

Ex:

validator(
   ['start' => new DateTime('2012-01-01'), 'ends' => new DateTime('2013-01-01')], 
   ['start' => 'date|Before:ends', 'ends' => 'date|After:start']
);

Or:

validator(
   ['start' => new Carbon('2012-01-01'), 'ends' => new Carbon('2013-01-01')], 
   ['start' => 'date|Before:ends', 'ends' => 'date|After:start']
);

@@ -1758,19 +1757,19 @@ protected function validateBefore($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'before');

if (! is_string($value) && ! is_numeric($value) && ! $value instanceof Carbon) {
if (! is_string($value) && ! is_numeric($value) && ! $value instanceof DateTime) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to check for DateTimeInterface perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Taylor already did, btw.

@taylorotwell taylorotwell merged commit 247b414 into laravel:5.2 Jun 3, 2016
@KennedyTedesco KennedyTedesco deleted the validation-5.2 branch June 3, 2016 14:23
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