diff --git a/composer.json b/composer.json index 2cdc960..a7781a1 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,9 @@ }, "require": { "php": ">=5.3.0", - "illuminate/support": "~4.1", - "illuminate/database": "~4.1", - "illuminate/validation": "~4.1" + "illuminate/support": "~5.0", + "illuminate/database": "~5.0", + "illuminate/validation": "~5.0" }, "autoload": { "psr-0": { diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..1178ef0 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -515,7 +515,27 @@ public function validate(array $rules = array(), array $customMessages = array() // check for overrides, then remove any empty rules $rules = (empty($rules))? static::$rules : $rules; + + // make sure primary key is validated + if (!isset($rules[$this->primaryKey])) { + $rules[$this->primaryKey] = 'unique:'.$this->table; + } + foreach ($rules as $field => $rls) { + + // check if unique fields have been modified or not, if not, exclude them from validation + $uPos = strpos($rls, 'unique'); + + if ($uPos !== false) { + // didnt change + if ($this->$field == $this->getOriginal($field)) { + // remove the unique rule as field didnt change + $uEPos = strpos($rls, '|', $uPos); + $uEPos = $uEPos ? $uEPos : strlen($rls); + $rules[$field] = substr($rls, 0, $uPos) . substr($rls, $uEPos); + } + } + if ($rls == '') { unset($rules[$field]); }