Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to add custom attributes #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Laracasts/Validation/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ interface FactoryInterface {
* @param array $messages
* @return ValidatorInterface
*/
public function make(array $formData, array $rules, array $messages = []);
public function make(array $formData, array $rules, array $messages = [], array $customAttributes = []);

}
16 changes: 15 additions & 1 deletion src/Laracasts/Validation/FormValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ abstract class FormValidator {
*/
protected $messages = [];

/**
* @var array
*/
protected $customAttributes = [];

/**
* @param ValidatorFactory $validator
*/
Expand All @@ -42,7 +47,8 @@ public function validate($formData)
$this->validation = $this->validator->make(
$formData,
$this->getValidationRules(),
$this->getValidationMessages()
$this->getValidationMessages(),
$this->getCustomAttributes()
);

if ($this->validation->fails())
Expand All @@ -53,6 +59,14 @@ public function validate($formData)
return true;
}

/**
* @return array
*/
public function getCustomAttributes()
{
return $this->customAttributes;
}

/**
* @return array
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Laracasts/Validation/LaravelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ function __construct(Validator $validator)
* @param array $formData
* @param array $rules
* @param array $messages
* @param array $customAttributes
* @return \Illuminate\Validation\Validator
*/
public function make(array $formData, array $rules, array $messages = [])
public function make(array $formData, array $rules, array $messages = [], array $customAttributes = [])
{
return $this->validator->make($formData, $rules, $messages);
return $this->validator->make($formData, $rules, $messages, $customAttributes);
}

}