Commit 72d181b3 authored by Taylor Otwell's avatar Taylor Otwell

added exists method and language lines for ip and exists rules.

parent 429ac00f
......@@ -47,9 +47,11 @@ return array(
),
"confirmed" => "The :attribute confirmation does not match.",
"email" => "The :attribute format is invalid.",
"exists" => "The selected :attribute is invalid.",
"image" => "The :attribute must be an image.",
"in" => "The selected :attribute is invalid.",
"integer" => "The :attribute must be an integer.",
"ip" => "The :attribute must be a valid IP address.",
"max" => array(
"numeric" => "The :attribute must be less than :max.",
"file" => "The :attribute must be less than :max kilobytes.",
......
......@@ -406,7 +406,7 @@ class Validator {
/**
* Validate the uniqueness of an attribute value on a given database table.
*
* If a database column is not specified, the attribute name will be used.
* If a database column is not specified, the attribute will be used.
*
* @param string $attribute
* @param mixed $value
......@@ -417,7 +417,7 @@ class Validator {
{
// We allow the table column to be specified just in case the column does
// not have the same name as the attribute. It must be within the second
// parameter position, right after the databse table name.
// parameter position, right after the database table name.
if (isset($parameters[1])) $attribute = $parameters[1];
$query = $this->db()->table($parameters[0])->where($attribute, '=', $value);
......@@ -432,7 +432,41 @@ class Validator {
return $query->count() == 0;
}
/**
* Validate the existence of an attribute value in a database table.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validate_exists($attribute, $value, $parameters)
{
if (isset($parameters[1])) $attribute = $parameters[1];
// Grab the number of elements we are looking for. If the given value is
// in array, we'll count all of the values in the array, otherwise we
// can just make sure the count is greater or equal to one.
$count = (is_array($value)) ? count($value) : 1;
$query = $this->db()->table($parameters[0]);
// If the given value is an array, we will check for the existence of
// all the values in the database, otherwise we'll check for the
// presence of the single given value in the database.
if (is_array($value))
{
$query = $query->where_in($attribute, $value);
}
else
{
$query = $query->where($attribute, '=', $value);
}
return $query->count() >= $count;
}
/**
* Validate that an attribute is a valid IP.
*
......
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