Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
fixed conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoriogo committed Jul 17, 2014
2 parents 34bd7c3 + 8af3cf8 commit d20f68a
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ abstract class Ardent extends Model {
*/
public static $customAttributes = array();

/**
* The validator object in case you need it externally (say, for a form builder).
*
* @see getValidator()
* @var \Illuminate\Validation\Validator
*/
protected $validator;

/**
* The message bag instance containing validation error messages
*
Expand Down Expand Up @@ -535,8 +543,8 @@ public function validate(array $rules = array(), array $customMessages = array()
$data = $this->getAttributes(); // the data under validation

// perform validation
$validator = static::makeValidator($data, $rules, $customMessages, $customAttributes);
$success = $validator->passes();
$this->validator = static::makeValidator($data, $rules, $customMessages, $customAttributes);
$success = $this->validator->passes();

if ($success) {
// if the model is valid, unset old errors
Expand All @@ -545,7 +553,7 @@ public function validate(array $rules = array(), array $customMessages = array()
}
} else {
// otherwise set the new ones
$this->validationErrors = $validator->messages();
$this->validationErrors = $this->validator->messages();

// stash the input to the current session
if (!self::$externalValidator && Input::hasSession()) {
Expand Down Expand Up @@ -789,7 +797,8 @@ protected function buildUniqueExclusionRules(array $rules = array()) {

foreach ($ruleset as &$rule) {
if (strpos($rule, 'unique') === 0) {
$params = explode(',', $rule);
// Stop splitting at 4 so final param will hold optional where clause
$params = explode(',', $rule, 4);

$uniqueRules = array();

Expand All @@ -808,7 +817,9 @@ protected function buildUniqueExclusionRules(array $rules = array()) {

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

// If optional where rules are passed, append them otherwise use primary key
$uniqueRules[4] = isset($params[3]) ? $params[3] : $this->primaryKey;
}
else {
$uniqueRules[3] = $this->id;
Expand Down Expand Up @@ -899,4 +910,12 @@ public function newQuery($excludeDeleted = true) {

return $builder;
}

/**
* Returns the validator object created after {@link validate()}.
* @return \Illuminate\Validation\Validator
*/
public function getValidator() {
return $this->validator;
}
}

0 comments on commit d20f68a

Please sign in to comment.