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]);