From 732630835792377c3646f6ce5a69d371f7a76fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wemerson=20C=2E=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2014 13:55:00 -0300 Subject: [PATCH 01/19] Fix ->validationErrors->count() when the object is null --- 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 e906e68..affc0ca 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -538,9 +538,11 @@ public function validate(array $rules = array(), array $customMessages = array() if ($success) { // if the model is valid, unset old errors - if ($this->validationErrors->count() > 0) { - $this->validationErrors = new MessageBag; - } + if($this->validationErrors === null){ + $this->validationErrors = new MessageBag; + }elseif($this->validationErrors->count() > 0) { + $this->validationErrors = new MessageBag; + } } else { // otherwise set the new ones $this->validationErrors = $this->validator->messages(); From 6f1633412be78de3590640ef7174e0a3fb0e94a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wemerson=20Couto=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2014 14:03:53 -0300 Subject: [PATCH 02/19] Update Ardent.php --- src/LaravelBook/Ardent/Ardent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index affc0ca..ea5d29a 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -539,10 +539,10 @@ public function validate(array $rules = array(), array $customMessages = array() if ($success) { // if the model is valid, unset old errors if($this->validationErrors === null){ - $this->validationErrors = new MessageBag; - }elseif($this->validationErrors->count() > 0) { - $this->validationErrors = new MessageBag; - } + $this->validationErrors = new MessageBag; + }elseif($this->validationErrors->count() > 0) { + $this->validationErrors = new MessageBag; + } } else { // otherwise set the new ones $this->validationErrors = $this->validator->messages(); From fa3b47b014f9b0e195f9b6ffac826a63254b89be Mon Sep 17 00:00:00 2001 From: Danniken Date: Tue, 5 Aug 2014 12:48:35 -0300 Subject: [PATCH 03/19] add translation to pt_BR --- src/LaravelBook/lang/pt-br/validation.php | 93 +++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/LaravelBook/lang/pt-br/validation.php diff --git a/src/LaravelBook/lang/pt-br/validation.php b/src/LaravelBook/lang/pt-br/validation.php new file mode 100644 index 0000000..f02a4e9 --- /dev/null +++ b/src/LaravelBook/lang/pt-br/validation.php @@ -0,0 +1,93 @@ + array( + /* + |-------------------------------------------------------------------------- + | Validation Language Lines + |-------------------------------------------------------------------------- + | + | The following language lines contain the default error messages used by + | the validator class. Some of these rules have multiple versions such + | such as the size rules. Feel free to tweak each of these messages. + | + */ + + "accepted" => "O campo :attribute deve ser marcado", + "active_url" => "O campo :attribute não é uma URL válida.", + "after" => "O campo :attribute deve ser uma data após :date.", + "alpha" => "O campo :attribute só pode conter letras.", + "alpha_dash" => "O campo :attribute só pode conter letras, números e hífens..", + "alpha_num" => "O campo :attribute só pode conter letras e números", + "before" => "O campo :attribute só pode conter uma data antes de :date.", + "between" => array( + "numeric" => "O campo :attribute deve conter valores entre :min - :max.", + "file" => "O campo :attribute deve ter o tamanho entre :min - :max kilobytes.", + "string" => "O campo :attribute deve ter entre :min - :max caracteres.", + ), + "confirmed" => "A confirmação do campo :attribute não corresponde.", + "date" => "O campo :attribute contém uma data inválida.", + "date_format" => "O campo :attribute não conrrespode ao formato :format.", + "different" => "Os campos :attribute e :other devem ser diferentes.", + "digits" => "O campo :attribute deve ser :digits digitos.", + "digits_between" => "O campo :attribute deve estar entre :min e :max digitos.", + "email" => "O campo :attribute tem formato inválido.", + "exists" => "O campo selecionado :attribute é inválido.", + "image" => "O campo :attribute deve conter uma imagem.", + "in" => "O valor selecionado em :attribute é invalido.", + "integer" => "O campo :attribute deve conter um valor númerico.", + "ip" => "O campo :attribute deve conter um endereço de IP válido.", + "max" => array( + "numeric" => "O campo :attribute não pode ser maior que :max.", + "file" => "O campo :attribute não pode ser maior que :max kilobytes.", + "string" => "O campo :attribute não pode ser maior que :max caracteres.", + ), + "mimes" => "O campo :attribute deve conter um arquivo do tipo: :values.", + "min" => array( + "numeric" => "O campo :attribute deve ser no mínimo :min.", + "file" => "O campo :attribute deve ser no mínimo :min kilobytes.", + "string" => "O campo :attribute deve ser no mínimo :min caracteres.", + ), + "not_in" => "O campo :attribute selecionado é inválido.", + "numeric" => "O campo :attribute deve ser númerico.", + "regex" => "O campo :attribute é inválido.", + "required" => "O campo :attribute é obrigatório.", + "required_if" => "O campo :attribute é obrigatório quando :other é :value.", + "required_with" => "O campo :attribute é obrigatório quando :values está presente.", + "required_without" => "O campo :attribute é obrigatório quando :values não está presente.", + "same" => "Os campos :attribute e :other devem conrrespoder.", + "size" => array( + "numeric" => "O campo :attribute deve ser :size.", + "file" => "O campo :attribute deve ser de :size kilobytes.", + "string" => "O campo :attribute deve ser de :size caracteres.", + ), + "unique" => "O campo :attribute já existe.", + "url" => "O campo :attribute tem formato inválido.", + + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => array(), + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ + + 'attributes' => array(), + ) +); From 9e2a94bbfcfcfb16e35596ca09e6583309f4f380 Mon Sep 17 00:00:00 2001 From: LF Bittencourt Date: Fri, 8 Aug 2014 18:13:04 -0300 Subject: [PATCH 04/19] buildUniqueExclusionRules table name bugfix. --- src/LaravelBook/Ardent/Ardent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..20f8ed7 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -795,7 +795,7 @@ protected function buildUniqueExclusionRules(array $rules = array()) { // Append table name if needed $table = explode(':', $params[0]); if (count($table) == 1) - $uniqueRules[1] = $this->table; + $uniqueRules[1] = $this->getTable(); else $uniqueRules[1] = $table[1]; From 4418043cd84e795051e8e05b21198807dfedb7cd Mon Sep 17 00:00:00 2001 From: Aleksey Soveliev Date: Wed, 17 Dec 2014 16:44:06 +0300 Subject: [PATCH 05/19] Update Ardent.php --- src/LaravelBook/Ardent/Ardent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..2d58243 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -570,7 +570,7 @@ public function validate(array $rules = array(), array $customMessages = array() * @param Closure $beforeSave * @param Closure $afterSave * @param bool $force Forces saving invalid data. - + * * @return bool * @see Ardent::save() * @see Ardent::forceSave() From fa5f21ad0889dfdb125760676bbbade0313a246a Mon Sep 17 00:00:00 2001 From: Andy Raines Date: Fri, 2 Jan 2015 13:52:57 +0000 Subject: [PATCH 06/19] Changed buildUnqiueExclusionRules to aid compatibility with unique_with validator. Same as issue #231 but doesnt involve all the formatting changes --- src/LaravelBook/Ardent/Ardent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..4c49f4f 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -786,7 +786,7 @@ protected function buildUniqueExclusionRules(array $rules = array()) { $ruleset = (is_string($ruleset))? explode('|', $ruleset) : $ruleset; foreach ($ruleset as &$rule) { - if (strpos($rule, 'unique') === 0) { + if (strpos($rule, 'unique:') === 0) { // Stop splitting at 4 so final param will hold optional where clause $params = explode(',', $rule, 4); From 33b8f25e93218ef2f8f00027e5cf815d84e85b66 Mon Sep 17 00:00:00 2001 From: Samuel Cloete Date: Wed, 11 Feb 2015 13:01:53 +0200 Subject: [PATCH 07/19] $relation was being over-written with the calling function name. I picked this up when trying to associate a model relationship dynamically via $model->belongsTo($related, $foreignKey, $otherKey, $relation)->associate($relationModel); --- src/LaravelBook/Ardent/Ardent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..5127949 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -378,7 +378,7 @@ public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relat // If no foreign key was supplied, we can use a backtrace to guess the proper // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. - $relation = $caller['function']; + if(is_null($relation)) $relation = $caller['function']; if (is_null($foreignKey)) { $foreignKey = snake_case($relation).'_id'; From edbb6aa0757918c72284b2c70bd58319708d3a17 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Sun, 19 Apr 2015 15:17:08 +0530 Subject: [PATCH 08/19] Issue with local key relation ship --- src/LaravelBook/Ardent/Ardent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e906e68..ba7973e 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -321,8 +321,8 @@ protected function handleRelationalArray($relationName) { case self::HAS_ONE: case self::HAS_MANY: case self::BELONGS_TO: - $verifyArgs(array('foreignKey')); - return $this->$relationType($relation[1], $relation['foreignKey']); + $verifyArgs(['foreignKey', 'localKey']); + return $this->$relationType($relation[1], $relation['foreignKey'], $relation['localKey']); case self::BELONGS_TO_MANY: $verifyArgs(array('table', 'foreignKey', 'otherKey')); From 646b95c472129ec778f9e0c00b7c4e8a8f9dd96f Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sat, 9 May 2015 12:51:09 -0300 Subject: [PATCH 09/19] Improving license and copyright info - Adding name to license and updating year - Updating readme copyright year - Adding license name - changing license to markdown --- LICENSE => LICENSE.md | 7 ++++--- README.md | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) rename LICENSE => LICENSE.md (89%) diff --git a/LICENSE b/LICENSE.md similarity index 89% rename from LICENSE rename to LICENSE.md index d3c3dae..f97726d 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,5 +1,6 @@ -Copyright (c) 2013, Max Ehsan -All rights reserved. +# [BSD 3-clause New License](http://choosealicense.com/licenses/bsd-3-clause/) + +### Copyright (c) 2015 - Max Ehsan, Igor Santos. All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -21,4 +22,4 @@ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. \ No newline at end of file +SUCH DAMAGE. diff --git a/README.md b/README.md index d2abeed..87613e9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Self-validating smart models for Laravel Framework 4's Eloquent ORM. Based on the Aware bundle for Laravel 3 by Colby Rabideau. -Copyright (C) 2013-2014 [Max Ehsan](http://laravelbook.com/) & [Igor Santos](http://www.igorsantos.com.br) +Copyright (C) 2013-2015 [Max Ehsan](http://laravelbook.com/) & [Igor Santos](http://www.igorsantos.com.br) ## Installation From 5e8ef7695db0012885dbdb6707e9ade87f9d9309 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 00:57:24 -0300 Subject: [PATCH 10/19] Adding support for correct params on Belongs To relations. localKey was renamed to otherKey, as the original Eloquent method --- src/LaravelBook/Ardent/Ardent.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index e81ee22..4295b02 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -320,10 +320,13 @@ protected function handleRelationalArray($relationName) { switch ($relationType) { case self::HAS_ONE: case self::HAS_MANY: - case self::BELONGS_TO: $verifyArgs(['foreignKey', 'localKey']); return $this->$relationType($relation[1], $relation['foreignKey'], $relation['localKey']); + case self::BELONGS_TO: + $verifyArgs(['foreignKey', 'otherKey', 'relation']); + return $this->$relationType($relation[1], $relation['foreignKey'], $relation['otherKey'], $relation['relation']); + case self::BELONGS_TO_MANY: $verifyArgs(array('table', 'foreignKey', 'otherKey')); $relationship = $this->$relationType($relation[1], $relation['table'], $relation['foreignKey'], $relation['otherKey']); From 20fc03ae01333f47138562be2337cf1112a59266 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 01:22:33 -0300 Subject: [PATCH 11/19] Improvements to relationship methods and args - Adding 'relation' param to BelongsTo relations - Adding 'localKey' to MorphOne/MorphMany (refs #204) - Creating MorphToMany/MorphedByMany relations, as per #232 / @mklenk --- src/LaravelBook/Ardent/Ardent.php | 32 +++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 4295b02..cd86fe3 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -171,6 +171,8 @@ abstract class Ardent extends Model { * @see \Illuminate\Database\Eloquent\Model::morphTo * @see \Illuminate\Database\Eloquent\Model::morphOne * @see \Illuminate\Database\Eloquent\Model::morphMany + * @see \Illuminate\Database\Eloquent\Model::morphToMany + * @see \Illuminate\Database\Eloquent\Model::morphedByMany * * @var array */ @@ -190,6 +192,10 @@ abstract class Ardent extends Model { const MORPH_MANY = 'morphMany'; + const MORPH_TO_MANY = 'morphToMany'; + + const MORPHED_BY_MANY = 'morphedByMany'; + /** * Array of relations used to verify arguments used in the {@link $relationsData} * @@ -198,7 +204,8 @@ abstract class Ardent extends Model { protected static $relationTypes = array( self::HAS_ONE, self::HAS_MANY, self::BELONGS_TO, self::BELONGS_TO_MANY, - self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY + self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY, + self::MORPH_TO_MANY, self::MORPHED_BY_MANY ); /** @@ -208,7 +215,6 @@ abstract class Ardent extends Model { * @return \LaravelBook\Ardent\Ardent */ public function __construct(array $attributes = array()) { - parent::__construct($attributes); $this->validationErrors = new MessageBag; } @@ -328,12 +334,14 @@ protected function handleRelationalArray($relationName) { return $this->$relationType($relation[1], $relation['foreignKey'], $relation['otherKey'], $relation['relation']); case self::BELONGS_TO_MANY: - $verifyArgs(array('table', 'foreignKey', 'otherKey')); - $relationship = $this->$relationType($relation[1], $relation['table'], $relation['foreignKey'], $relation['otherKey']); - if(isset($relation['pivotKeys']) && is_array($relation['pivotKeys'])) + $verifyArgs(array('table', 'foreignKey', 'otherKey', 'relation')); + $relationship = $this->$relationType($relation[1], $relation['table'], $relation['foreignKey'], $relation['otherKey'], $relation['relation']); + if(isset($relation['pivotKeys']) && is_array($relation['pivotKeys'])) { $relationship->withPivot($relation['pivotKeys']); - if(isset($relation['timestamps']) && $relation['timestamps']==true) + } + if(isset($relation['timestamps']) && $relation['timestamps']) { $relationship->withTimestamps(); + } return $relationship; case self::MORPH_TO: @@ -342,8 +350,16 @@ protected function handleRelationalArray($relationName) { case self::MORPH_ONE: case self::MORPH_MANY: - $verifyArgs(array('type', 'id'), array('name')); - return $this->$relationType($relation[1], $relation['name'], $relation['type'], $relation['id']); + $verifyArgs(array('type', 'id', 'localKey'), array('name')); + return $this->$relationType($relation[1], $relation['name'], $relation['type'], $relation['id'], $relation['localKey']); + + case self::MORPH_TO_MANY: + $verifyArgs(array('table', 'foreignKey', 'otherKey', 'inverse'), array('name')); + return $this->$relationType($relation[1], $relation['name'], $relation['table'], $relation['foreignKey'], $relation['otherKey'], $relation['inverse']); + + case self::MORPHED_BY_MANY: + $verifyArgs(array('table', 'foreignKey', 'otherKey'), array('name')); + return $this->$relationType($relation[1], $relation['name'], $relation['table'], $relation['foreignKey'], $relation['otherKey']); } } From 2a5e554a6e40fa566a8458ace70be08c857e9225 Mon Sep 17 00:00:00 2001 From: samuel-cloete Date: Sun, 10 May 2015 07:16:28 +0200 Subject: [PATCH 12/19] Wrap the whole backtrace in the if clause as it might not be needed. --- 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 5127949..5585da1 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -372,13 +372,15 @@ public function __call($method, $parameters) { * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relation = NULL) { - $backtrace = debug_backtrace(false); - $caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1]; // If no foreign key was supplied, we can use a backtrace to guess the proper // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. - if(is_null($relation)) $relation = $caller['function']; + if (is_null($relation)) { + $backtrace = debug_backtrace(false); + $caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1]; + $relation = $caller['function']; + } if (is_null($foreignKey)) { $foreignKey = snake_case($relation).'_id'; From b15f364d45f3f6c07a1b815776722d67a6355101 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 03:37:02 -0300 Subject: [PATCH 13/19] Fixing coding issues pointed out to @wemersonrv in #225 This merge closes #225 and #171. refs #128 --- src/LaravelBook/Ardent/Ardent.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 76032c4..9c2dd65 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -559,9 +559,7 @@ public function validate(array $rules = array(), array $customMessages = array() if ($success) { // if the model is valid, unset old errors - if($this->validationErrors === null){ - $this->validationErrors = new MessageBag; - }elseif($this->validationErrors->count() > 0) { + if ($this->validationErrors === null || $this->validationErrors->count() > 0) { $this->validationErrors = new MessageBag; } } else { From 71cbe2bee7f5e0bf7c8c6b4a8b4009c727d5ebba Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 03:54:05 -0300 Subject: [PATCH 14/19] Including support for hasManyThrough, as per @khaeransori at commit 36cecc7 --- src/LaravelBook/Ardent/Ardent.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 9c2dd65..4c5bb11 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -166,6 +166,7 @@ abstract class Ardent extends Model { * * @see \Illuminate\Database\Eloquent\Model::hasOne * @see \Illuminate\Database\Eloquent\Model::hasMany + * @see \Illuminate\Database\Eloquent\Model::hasManyThrough * @see \Illuminate\Database\Eloquent\Model::belongsTo * @see \Illuminate\Database\Eloquent\Model::belongsToMany * @see \Illuminate\Database\Eloquent\Model::morphTo @@ -182,6 +183,8 @@ abstract class Ardent extends Model { const HAS_MANY = 'hasMany'; + const HAS_MANY_THROUGH = 'hasManyThrough'; + const BELONGS_TO = 'belongsTo'; const BELONGS_TO_MANY = 'belongsToMany'; @@ -202,7 +205,7 @@ abstract class Ardent extends Model { * @var array */ protected static $relationTypes = array( - self::HAS_ONE, self::HAS_MANY, + self::HAS_ONE, self::HAS_MANY, self::HAS_MANY_THROUGH, self::BELONGS_TO, self::BELONGS_TO_MANY, self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY, self::MORPH_TO_MANY, self::MORPHED_BY_MANY @@ -329,12 +332,16 @@ protected function handleRelationalArray($relationName) { $verifyArgs(['foreignKey', 'localKey']); return $this->$relationType($relation[1], $relation['foreignKey'], $relation['localKey']); + case self::HAS_MANY_THROUGH: + $verifyArgs(['firstKey', 'secondKey'], ['through']); + return $this->$relationType($relation[1], $relation['through'], $relation['firstKey'], $relation['secondKey']); + case self::BELONGS_TO: $verifyArgs(['foreignKey', 'otherKey', 'relation']); return $this->$relationType($relation[1], $relation['foreignKey'], $relation['otherKey'], $relation['relation']); case self::BELONGS_TO_MANY: - $verifyArgs(array('table', 'foreignKey', 'otherKey', 'relation')); + $verifyArgs(['table', 'foreignKey', 'otherKey', 'relation']); $relationship = $this->$relationType($relation[1], $relation['table'], $relation['foreignKey'], $relation['otherKey'], $relation['relation']); if(isset($relation['pivotKeys']) && is_array($relation['pivotKeys'])) { $relationship->withPivot($relation['pivotKeys']); @@ -345,20 +352,20 @@ protected function handleRelationalArray($relationName) { return $relationship; case self::MORPH_TO: - $verifyArgs(array('name', 'type', 'id')); + $verifyArgs(['name', 'type', 'id']); return $this->$relationType($relation['name'], $relation['type'], $relation['id']); case self::MORPH_ONE: case self::MORPH_MANY: - $verifyArgs(array('type', 'id', 'localKey'), array('name')); + $verifyArgs(['type', 'id', 'localKey'], ['name']); return $this->$relationType($relation[1], $relation['name'], $relation['type'], $relation['id'], $relation['localKey']); case self::MORPH_TO_MANY: - $verifyArgs(array('table', 'foreignKey', 'otherKey', 'inverse'), array('name')); + $verifyArgs(['table', 'foreignKey', 'otherKey', 'inverse'], ['name']); return $this->$relationType($relation[1], $relation['name'], $relation['table'], $relation['foreignKey'], $relation['otherKey'], $relation['inverse']); case self::MORPHED_BY_MANY: - $verifyArgs(array('table', 'foreignKey', 'otherKey'), array('name')); + $verifyArgs(['table', 'foreignKey', 'otherKey'], ['name']); return $this->$relationType($relation[1], $relation['name'], $relation['table'], $relation['foreignKey'], $relation['otherKey']); } } From e640dee896319532da80fe9e2c3851e0c26cd23a Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 04:07:09 -0300 Subject: [PATCH 15/19] Max was removed from authors list since he has completely abandoned the project without distributing it's permissions --- composer.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.json b/composer.json index 2cdc960..feffc6b 100644 --- a/composer.json +++ b/composer.json @@ -6,12 +6,6 @@ "homepage": "http://laravelbook.com/", "license": "BSD-3-Clause", "authors": [ - { - "name": "Max Ehsan", - "homepage": "http://laravelbook.com/", - "email": "contact@laravelbook.com", - "role": "Developer" - }, { "name": "Igor Santos", "homepage": "http://www.igorsantos.com.br", From ddc6cbf04001a23f4c82533a82d93da7998e6269 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Sun, 10 May 2015 04:36:18 -0300 Subject: [PATCH 16/19] Adding support for multiple languages. refs #234 --- README.md | 2 +- src/LaravelBook/Ardent/Ardent.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 87613e9..4a59e56 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ to your database, obviously): 'password' => 'h4ckr', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci' -)); +), 'en'); //English is the default messages language, may be left empty ``` ------------------------------------------------------------------------------------------------------------ diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 4c5bb11..140410f 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -134,7 +134,7 @@ abstract class Ardent extends Model { protected static $externalValidator = false; /** - * A Translator instance, to be used by standalone Ardent instances. + * A Validation Factory instance, to be used by standalone Ardent instances with the Translator. * * @var \Illuminate\Validation\Factory */ @@ -484,7 +484,7 @@ public function getAttribute($key) { * @param array $connection Connection info used by {@link \Illuminate\Database\Capsule\Manager::addConnection}. * Should contain driver, host, port, database, username, password, charset and collation. */ - public static function configureAsExternal(array $connection) { + public static function configureAsExternal(array $connection, $lang = 'en') { $db = new DatabaseCapsule; $db->addConnection($connection); $db->setEventDispatcher(new Dispatcher(new Container)); @@ -495,11 +495,11 @@ public static function configureAsExternal(array $connection) { $db->bootEloquent(); - $translator = new Translator('en'); + $translator = new Translator($lang); $translator->addLoader('file_loader', new PhpFileLoader()); $translator->addResource('file_loader', - dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'en'. - DIRECTORY_SEPARATOR.'validation.php', 'en'); + dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$lang. + DIRECTORY_SEPARATOR.'validation.php', $lang); self::$externalValidator = true; self::$validationFactory = new ValidationFactory($translator); From b3eb96303149182da8e4127d2aca00e16082f0a5 Mon Sep 17 00:00:00 2001 From: Chris Konnertz Date: Thu, 21 May 2015 13:05:37 +0200 Subject: [PATCH 17/19] Updated the newQuery() method Updated the newQuery() method so that it does not use old soft deleting stuff any more --- src/LaravelBook/Ardent/Ardent.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/LaravelBook/Ardent/Ardent.php b/src/LaravelBook/Ardent/Ardent.php index 140410f..ba6f026 100755 --- a/src/LaravelBook/Ardent/Ardent.php +++ b/src/LaravelBook/Ardent/Ardent.php @@ -921,12 +921,7 @@ public function newQuery($excludeDeleted = true) { // while it is constructing and executing various queries against it. $builder->setModel($this)->with($this->with); - if ($excludeDeleted and $this->softDelete) - { - $builder->whereNull($this->getQualifiedDeletedAtColumn()); - } - - return $builder; + return $this->applyGlobalScopes($builder); } /** From 1c4e983a119649725835ad16f118a2632aae16fa Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Thu, 28 May 2015 19:14:12 -0300 Subject: [PATCH 18/19] Adding mention about changelog --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4a59e56..4df8356 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ Based on the Aware bundle for Laravel 3 by Colby Rabideau. Copyright (C) 2013-2015 [Max Ehsan](http://laravelbook.com/) & [Igor Santos](http://www.igorsantos.com.br) +## Changelog + +Visit our [Releases list](https://github.com/laravelbook/ardent/releases). The changelog is made there :) ## Installation From 2f83aa7482fa5c032c233b4169316ef223eb19f3 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Thu, 28 May 2015 19:16:14 -0300 Subject: [PATCH 19/19] Adding changelog file with reference to releases --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8466dc1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +Ardent's Changelog +================== + +Please, look at the [project's release][1] page :) + +[1]:https://github.com/laravelbook/ardent/releases