Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
Closed
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
19 changes: 17 additions & 2 deletions src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ abstract class Ardent extends Model {
*/
public static $customMessages = array();

/**
* The array of custom attributes names in error messages
*
* @var array
*/
public static $niceNames = array();

/**
* The validator object in case you need it externally (say, for a form builder).
*
Expand Down Expand Up @@ -529,10 +536,11 @@ protected static function makeValidator($data, $rules, $customMessages) {
*
* @param array $rules Validation rules
* @param array $customMessages Custom error messages
* @param array $niceNames Custom attributes names on error messages
* @return bool
* @throws InvalidModelException
*/
public function validate(array $rules = array(), array $customMessages = array()) {
public function validate(array $rules = array(), array $customMessages = array(), array $niceNames = array()) {
if ($this->fireModelEvent('validating') === false) {
if ($this->throwOnValidation) {
throw new InvalidModelException($this);
Expand Down Expand Up @@ -562,7 +570,14 @@ public function validate(array $rules = array(), array $customMessages = array()

// perform validation
$this->validator = static::makeValidator($data, $rules, $customMessages);
$success = $this->validator->passes();

//set custom attribute names
if (method_exists($this->validator, 'setAttributeNames')) {
$niceNames = (empty($niceNames))? static::$niceNames : $niceNames;
$this->validator->setAttributeNames($niceNames);
}

$success = $this->validator->passes();

if ($success) {
// if the model is valid, unset old errors
Expand Down