Commit 5cbebb99 by Taylor Otwell

Merge pull request #436 from daylerees/date-filters

Date before and after filters
parents 0961f8f7 533112e2
...@@ -59,6 +59,8 @@ return array( ...@@ -59,6 +59,8 @@ return array(
), ),
"unique" => "The :attribute has already been taken.", "unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.", "url" => "The :attribute format is invalid.",
"before" => "The :attribute field must contain a date before :date.",
"after" => "The :attribute field must contain a date after :date.",
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
...@@ -647,6 +647,32 @@ class Validator { ...@@ -647,6 +647,32 @@ class Validator {
} }
/** /**
* Validate the date is before a given date.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validate_before($attribute, $value, $parameters)
{
return (strtotime($value) < strtotime($parameters[0]));
}
/**
* Validate the date is after a given date.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validate_after($attribute, $value, $parameters)
{
return (strtotime($value) > strtotime($parameters[0]));
}
/**
* Get the proper error message for an attribute and rule. * Get the proper error message for an attribute and rule.
* *
* @param string $attribute * @param string $attribute
...@@ -878,6 +904,34 @@ class Validator { ...@@ -878,6 +904,34 @@ class Validator {
} }
/** /**
* Replace all place-holders for the before rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replace_before($message, $attribute, $rule, $parameters)
{
return str_replace(':date', $parameters[0], $message);
}
/**
* Replace all place-holders for the after rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replace_after($message, $attribute, $rule, $parameters)
{
return str_replace(':date', $parameters[0], $message);
}
/**
* Get the displayable name for a given attribute. * Get the displayable name for a given attribute.
* *
* @param string $attribute * @param string $attribute
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment