Skip to content

Commit

Permalink
Add posibility to specify custom attributes names
Browse files Browse the repository at this point in the history
Resolves crhayes#11
  • Loading branch information
melihovv committed Aug 28, 2016
1 parent 1df2d4c commit 7b1efa7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class UserValidator extends ContextualValidator
protected $messages = [
'first_name.required' => 'First name is required!'
];

protected $attributeNames = [
'last_name' => 'Last Name'
];
}
```
This service is then instantiated and the validation works much the same as Laravel's built-in validation.
Expand Down
14 changes: 13 additions & 1 deletion src/Crhayes/Validation/ContextualValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ abstract class ContextualValidator implements MessageProvider
*/
protected $messages = array();

/**
* Store any custom names of attributes.
*
* @var array
*/
protected $attributeNames = array();

/**
* Store any contexts we are validating within.
*
Expand Down Expand Up @@ -182,7 +189,12 @@ public function passes()
{
$rules = $this->bindReplacements($this->getRulesInContext());

$validator = Validator::make($this->attributes, $rules, $this->messages);
$validator = Validator::make(
$this->attributes,
$rules,
$this->messages,
$this->attributeNames
);

$this->addConditionalRules($validator);

Expand Down

0 comments on commit 7b1efa7

Please sign in to comment.