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

/**
* The array of custom attributes.
*
* @var array
*/
public static $customAttributes = array();

/**
* The validator object in case you need it externally (say, for a form builder).
*
* @see getValidator()
Expand Down Expand Up @@ -513,26 +520,28 @@ public static function configureAsExternal(array $connection, $lang = 'en') {
* @param $data
* @param $rules
* @param $customMessages
* @param $customAttributes
* @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);
}
}

/**
* 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);
Expand All @@ -553,6 +562,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's this variable coming from? $customMessages is an argument but the new one is not. Please include it in the method signatures if it makes sense (I guess it does although I'm no Laravel expert) or simply remove this check altogether and use static::$customAttributes directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. $customAttributes parameter included!


if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) {
$this->fill(Input::all());
Expand All @@ -561,7 +571,7 @@ public function validate(array $rules = array(), array $customMessages = array()
$data = $this->getAttributes(); // the data under validation

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

if ($success) {
Expand Down