From 1f336034600e2fd8eb5648f5e60a52d66bda4cb9 Mon Sep 17 00:00:00 2001 From: Piotr Kurpiewski Date: Tue, 9 Apr 2019 12:50:26 +0200 Subject: [PATCH] dont increase the frequancy field if its null --- src/Taggable.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Taggable.php b/src/Taggable.php index 96dc470..a40f1e6 100644 --- a/src/Taggable.php +++ b/src/Taggable.php @@ -163,7 +163,9 @@ public function afterSave($event) $tag->{$this->name} = $name; } - $tag->{$this->frequency}++; + if (!is_null($tag->{$this->frequency})) { + $tag->{$this->frequency}++; + } if ($tag->save()) { $updatedTags[] = $tag; @@ -205,7 +207,7 @@ public function beforeDelete($event) ->createCommand() ->delete($pivot, [key($relation->via->link) => $this->owner->getPrimaryKey()]) ->execute(); - + if ($this->removeUnusedTags) { $class::deleteAll([$this->frequency => 0]);