diff --git a/src/Laracasts/Validation/FactoryInterface.php b/src/Laracasts/Validation/FactoryInterface.php index 6764357..bdba70b 100644 --- a/src/Laracasts/Validation/FactoryInterface.php +++ b/src/Laracasts/Validation/FactoryInterface.php @@ -8,8 +8,9 @@ interface FactoryInterface { * @param array $formData * @param array $rules * @param array $messages + * @param array $attributeNames * @return ValidatorInterface */ - public function make(array $formData, array $rules, array $messages = []); + public function make(array $formData, array $rules, array $messages = [], array $attributeNames = []); -} +} diff --git a/src/Laracasts/Validation/FormValidator.php b/src/Laracasts/Validation/FormValidator.php index ec4fd62..e0fbba4 100644 --- a/src/Laracasts/Validation/FormValidator.php +++ b/src/Laracasts/Validation/FormValidator.php @@ -20,6 +20,11 @@ abstract class FormValidator { */ protected $messages = []; + /** + * @var array + */ + protected $attributeNames = []; + /** * @param ValidatorFactory $validator */ @@ -42,7 +47,8 @@ public function validate($formData) $this->validation = $this->validator->make( $formData, $this->getValidationRules(), - $this->getValidationMessages() + $this->getValidationMessages(), + $this->getAttributeNames() ); if ($this->validation->fails()) @@ -70,13 +76,21 @@ public function getValidationErrors() } /** - * @return mixed + * @return array */ public function getValidationMessages() { return $this->messages; } + /** + * @return array + */ + public function getAttributeNames() + { + return $this->attributeNames; + } + /** * Normalize the provided data to an array. * diff --git a/src/Laracasts/Validation/LaravelValidator.php b/src/Laracasts/Validation/LaravelValidator.php index 8cc7569..e6f1819 100644 --- a/src/Laracasts/Validation/LaravelValidator.php +++ b/src/Laracasts/Validation/LaravelValidator.php @@ -23,11 +23,16 @@ function __construct(Validator $validator) * @param array $formData * @param array $rules * @param array $messages + * @param array $attributeNames * @return \Illuminate\Validation\Validator */ - public function make(array $formData, array $rules, array $messages = []) + public function make(array $formData, array $rules, array $messages = [], array $attributeNames = []) { - return $this->validator->make($formData, $rules, $messages); + $validator = $this->validator->make($formData, $rules, $messages); + + $attributeNames && $validator->setAttributeNames($attributeNames); + + return $validator; } }