Commit 1fc86102 authored by Taylor Otwell's avatar Taylor Otwell

added back support for specifying column in validator unique rule. id is now a...

added back support for specifying column in validator unique rule. id is now a third parameter option.
parent 1ec6fc76
......@@ -417,11 +417,19 @@ class Validator {
{
if (is_null($this->db)) $this->db = Database::connection();
// 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 in the second
// parameter position, right after the databse table name.
if (isset($parameters[1])) $attribute = $parameters[1];
$query = $this->db->table($parameters[0])->where($attribute, '=', $value);
if (isset($parameters[1]))
// We also allow an ID to be specified that will not be included in the
// uniqueness check. This makes updating columns easier since it is
// fine for the given ID to exist in the table.
if (isset($parameters[2]))
{
$query->where('id', '<>', $parameters[1]);
$query->where('id', '<>', $parameters[2]);
}
return $query->count() == 0;
......
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