From 5790fece730867dca229dd57a0695581335f447d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 19 Oct 2016 07:20:28 +1100 Subject: [PATCH] addHashableAttribute -> addHashable Following pattern from addFillable() Tidy up code --- src/Database/Traits/Hashable.php | 13 ++++++++++++- src/Database/Traits/Nullable.php | 21 +++++++++++++++++++-- src/Database/Traits/Purgeable.php | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Database/Traits/Hashable.php b/src/Database/Traits/Hashable.php index 91191afe0..986d45150 100644 --- a/src/Database/Traits/Hashable.php +++ b/src/Database/Traits/Hashable.php @@ -45,7 +45,7 @@ public static function bootHashable() * @param array|string|null $attributes * @return $this */ - public function addHashableAttribute($attributes = null) + public function addHashable($attributes = null) { $attributes = is_array($attributes) ? $attributes : func_get_args(); @@ -105,4 +105,15 @@ public function getOriginalHashValue($attribute) ? $this->originalHashableValues[$attribute] : null; } + + /** + * @deprecated use self::addHashable() + * Remove this method if year >= 2018 + */ + public function addHashableAttribute($attribute) + { + traceLog('The addHashableAttribute() method is deprecated, use addHashable() instead.'); + + return $this->addHashable($attribute); + } } diff --git a/src/Database/Traits/Nullable.php b/src/Database/Traits/Nullable.php index 98240ead5..0df112f12 100644 --- a/src/Database/Traits/Nullable.php +++ b/src/Database/Traits/Nullable.php @@ -4,6 +4,11 @@ trait Nullable { + /** + * @var array List of attribute names which should be set to null when empty. + * + * protected $nullable = []; + */ /** * Boot the nullable trait for a model @@ -25,9 +30,22 @@ public static function bootNullable() }); } + /** + * Adds an attribute to the nullable attributes list + * @param array|string|null $attributes + * @return $this + */ + public function addNullable($attributes = null) + { + $attributes = is_array($attributes) ? $attributes : func_get_args(); + + $this->nullable = array_merge($this->nullable, $attributes); + + return $this; + } + /** * Nullify empty fields - * * @return void */ public function nullableBeforeSave() @@ -43,5 +61,4 @@ public function nullableBeforeSave() } } } - } diff --git a/src/Database/Traits/Purgeable.php b/src/Database/Traits/Purgeable.php index 019ac8286..1d2d6715a 100644 --- a/src/Database/Traits/Purgeable.php +++ b/src/Database/Traits/Purgeable.php @@ -41,7 +41,7 @@ public static function bootPurgeable() * @param array|string|null $attributes * @return $this */ - public function addPurgeableAttribute($attributes = null) + public function addPurgeable($attributes = null) { $attributes = is_array($attributes) ? $attributes : func_get_args();