Skip to content

Commit

Permalink
Addresses laravel-ardent#86 miss
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew13 committed Oct 21, 2013
1 parent 4d3b12d commit ffdf8ec
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,23 +759,38 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
$ruleset = (is_string($ruleset))? explode('|', $ruleset) : $ruleset;

foreach ($ruleset as &$rule) {
if (strpos($rule, 'unique') === 0) {
$params = explode(',', $rule);

// Append field name if needed
if (count($params) == 1) {
$params[1] = $field;
}

// if the 3rd param was set, do not overwrite it
if (!is_numeric(@$params[2])) $params[2] = $this->id;


$rule = implode(',', $params);
if (strpos($rule, 'unique') === 0) {
$params = explode(',', $rule);

$uniqueRules = array();

// Append table name if needed
$table = explode(':', $params[0]);
if (count($table) == 1)
$uniqueRules[1] = $this->table;
else
$uniqueRules[1] = $table[1];

// Append field name if needed
if (count($params) == 1)
$uniqueRules[2] = $field;
else
$uniqueRules[2] = $params[1];

if (isset($this->primaryKey)) {
$uniqueRules[3] = $this->{$this->primaryKey};
$uniqueRules[4] = $this->primaryKey;
}
}
else {
$uniqueRules[3] = $this->id;
}

$rule = 'unique:' . implode(',', $uniqueRules);
} // end if strpos unique

} // end foreach ruleset
}

return $rules;
}

Expand Down

0 comments on commit ffdf8ec

Please sign in to comment.