Skip to content

Commit

Permalink
handle & Exists queryCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Feb 27, 2017
1 parent 05e4e9e commit a7a8583
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Illuminate/Validation/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\Exists;
use Illuminate\Validation\Rules\Unique;

class ValidationRuleParser
{
Expand Down Expand Up @@ -82,12 +84,31 @@ protected function explodeExplicitRule($rule)
if (is_string($rule)) {
return explode('|', $rule);
} elseif (is_object($rule)) {
return [strval($rule)];
return [$this->prepareRule($rule)];
} else {
return array_map('strval', $rule);
return array_map([$this, 'prepareRule'], $rule);
}
}

/**
* Prepare the given rule for the Validator.
*
* @param mixed $rule
* @return mixed
*/
protected function prepareRule($rule)
{
if (
! is_object($rule) ||
($rule instanceof Exists && $rule->queryCallbacks()) ||
($rule instanceof Unique && $rule->queryCallbacks())
) {
return $rule;
}

return strval($rule);
}

/**
* Define a set of rules that apply to each element in an array attribute.
*
Expand Down

0 comments on commit a7a8583

Please sign in to comment.