spatie / laravel-tags

Add tags and taggable behaviour to your Laravel app
https://freek.dev/609-an-opinionated-tagging-package-for-laravel-apps
MIT License
1.62k stars 281 forks source link

Add isUsed() to Tag model #451

Closed jeremysalmon closed 1 year ago

jeremysalmon commented 1 year ago

Add isUsed() to check if a tag is used in database.

I use this method to check that a tag is unused and in this case delete it from the database.

image

For exemple when I click on the cross in livewire :

public function removeTag($tagName)
    {
        $tag = Tag::findFromString($tagName);
        $this->company->detachTag($tagName);
        $this->company->refresh();
        if(!$tag->isUsed()) {
            $tag->delete();
        }
    }
freekmurze commented 1 year ago

Thanks! I'm going to pass on this one, to keep the package light.

Add this in your own project.