From 8bd6d34622f59120a929d029b80ff414b9b0766d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 16 Oct 2011 13:25:37 -0500 Subject: [PATCH] refactoring validator. --- laravel/validation/validator.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/laravel/validation/validator.php b/laravel/validation/validator.php index 25c313b0..48b1192e 100644 --- a/laravel/validation/validator.php +++ b/laravel/validation/validator.php @@ -1,6 +1,7 @@ attributes[$attribute])) ? $this->attributes[$attribute] : null; + $value = Arr::get($this->attributes, $attribute); // No validation will be run for attributes that do not exist unless the // rule being validated is "required" or "accepted". No other rules have // implicit "required" checks for validation. - if ( ! $this->validate_required($attribute) and ! in_array($rule, array('required', 'accepted'))) return; + if ( ! $this->validate_required($attribute, $value) and ! in_array($rule, array('required', 'accepted'))) + { + return; + } if ( ! $this->$validator($attribute, $value, $parameters, $this)) { @@ -204,11 +208,7 @@ protected function error($attribute, $rule, $parameters) */ protected function validate_required($attribute, $value) { - if (is_null($value)) return false; - - if (is_string($value) and trim($value) === '') return false; - - return true; + return (is_null($value) or (is_string($value) and trim($value) === '')); } /**