From 15ca036b8e8c7f06df403f368929ddbfc31410be Mon Sep 17 00:00:00 2001 From: Ricardo Riogo Date: Sat, 14 Jun 2014 22:08:46 -0300 Subject: [PATCH 1/2] Added the possibility to define custom attributes's names on models --- src/LaravelBook/Ardent/Ardent.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 49386fd..4a572d6 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -45,6 +45,13 @@ abstract class Ardent extends Model { */ public static $customMessages = array(); + /** + * The array of custom attributes. + * + * @var array + */ + public static $customAttributes = array(); + /** * The message bag instance containing validation error messages * @@ -480,11 +487,11 @@ public static function configureAsExternal(array $connection) { * @return \Illuminate\Validation\Validator * @see Ardent::$externalValidator */ - protected static function makeValidator($data, $rules, $customMessages) { + protected static function makeValidator($data, $rules, $customMessages, $customAttributes) { if (self::$externalValidator) { - return self::$validationFactory->make($data, $rules, $customMessages); + return self::$validationFactory->make($data, $rules, $customMessages, $customAttributes); } else { - return Validator::make($data, $rules, $customMessages); + return Validator::make($data, $rules, $customMessages, $customAttributes); } } @@ -517,6 +524,7 @@ public function validate(array $rules = array(), array $customMessages = array() $success = true; } else { $customMessages = (empty($customMessages))? static::$customMessages : $customMessages; + $customAttributes = (empty($customAttributes))? static::$customAttributes : $customAttributes; if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) { $this->fill(Input::all()); @@ -525,7 +533,7 @@ public function validate(array $rules = array(), array $customMessages = array() $data = $this->getAttributes(); // the data under validation // perform validation - $validator = static::makeValidator($data, $rules, $customMessages); + $validator = static::makeValidator($data, $rules, $customMessages, $customAttributes); $success = $validator->passes(); if ($success) { From 34bd7c3714c7c4e90f4c8e679504dc13897f47c9 Mon Sep 17 00:00:00 2001 From: Ricardo Riogo Date: Wed, 9 Jul 2014 10:32:58 -0300 Subject: [PATCH 2/2] Update Ardent.php Added ``$customAttributes`` on ``Ardent::validate()`` signature. --- src/LaravelBook/Ardent/Ardent.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 4a572d6..5f03e86 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -484,6 +484,7 @@ public static function configureAsExternal(array $connection) { * @param $data * @param $rules * @param $customMessages + * @param $customAttributes * @return \Illuminate\Validation\Validator * @see Ardent::$externalValidator */ @@ -498,12 +499,13 @@ protected static function makeValidator($data, $rules, $customMessages, $customA /** * Validate the model instance * - * @param array $rules Validation rules - * @param array $customMessages Custom error messages + * @param array $rules Validation rules + * @param array $customMessages Custom error messages + * @param array $customAttributes Custom attributes * @return bool * @throws InvalidModelException */ - public function validate(array $rules = array(), array $customMessages = array()) { + public function validate(array $rules = array(), array $customMessages = array(), array $customAttributes = array()) { if ($this->fireModelEvent('validating') === false) { if ($this->throwOnValidation) { throw new InvalidModelException($this);