PHPackages                             priblo/laravel-has-tags - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. priblo/laravel-has-tags

ActiveLibrary[Database &amp; ORM](/categories/database)

priblo/laravel-has-tags
=======================

Performance centric model tags trait

v1.0.0-beta.5(7y ago)028MITPHPPHP &gt;=7.1.0

Since Mar 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Priblo/Laravel-Has-Tags)[ Packagist](https://packagist.org/packages/priblo/laravel-has-tags)[ RSS](/packages/priblo-laravel-has-tags/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

Laravel Has Tags
================

[](#laravel-has-tags)

##### Performance centric model tags trait

[](#performance-centric-model-tags-trait)

[![Build Status](https://camo.githubusercontent.com/552d3a77f8226d456204d6b8bbf162b72ad1da745924d20678d039f8a6f780a8/68747470733a2f2f7472617669732d63692e6f72672f507269626c6f2f4c61726176656c2d4861732d546167732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Priblo/Laravel-Has-Tags)

Trait Usage
-----------

[](#trait-usage)

Add the trait to any Eloqent model you need to become taggable:

```
Priblo\LaravelHasTags\Traits\HasTags;
```

Usage:

```
$Post = new Post();

// Tag Model
// (Duplicates are automatically handled)
$Post->tag(['tag1', 'tag2', 'tag3', 'tag1']);
// Tag Model with type
$Post->tag(['tag1', 'tag2', 'tag3', 'tag1'], 'hashtag');

// Count ALL tags attached to the model
$Post->tags->count()
// Count ONLY tags with type
$Post->tagsWithType('hashtag')->count()

// Retag model
// Will remove previous tags and add the new ones
// Type is optional
$Post->reTag(['tag5', 'tag6'],'hashtag');
// Removes ALL tags without type from Model
$Post->untag()
// Removes ONLY tags with the specified type from Model
$Post->untag('hashtag')
// Removes ALL tags from model
$Post->untagALL()

// Retrieves all tagged models with the specified tag and type (optional)
$posts = Post::withAnyTag(['tag1'],'hashtag')->get();

// Retrieves all related models according to Tag and type (optional)
// Returns a collection of Priblo\LaravelHasTags\Models\Related
$relatedCollection = Post::getRelatedByTag('tag1', 'hashtag));
```

**Note on types**

Every tag has a type, which if unspecified will be NULL, a null type is still a type, which means that using the `untag()` method will remove ONLY tags with `type === NULL`. This is a design choice.

Config
------

[](#config)

### Cache

[](#cache)

**Caching requires a driver which supports tags**. File and Database won't work, redis is suggested. Please make sure to either disable caching in the config or use the array driver for local development.

In the *has-tags.php* config file you can enable/disable caching and set the cache expiration time.

**Caching is enabled by default**

Install
-------

[](#install)

*Requires: Laravel &gt;=5.5 and PHP 7.1*

**Composer**

```
    composer require priblo/laravel-has-tags

```

**Laravel**

This package supports Auto Discovery.

If you have disabled it, you can install this package by adding to the 'providers' array in *./config/app.php*

```
Priblo\LaravelHasTags\LaravelServiceProvider::class,
```

Then run:

```
php artisan vendor:publish --provider="Priblo\LaravelHasTags\LaravelServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Priblo\LaravelHasTags\LaravelServiceProvider" --tag="config"

```

Then migrate:

```
php artisan migrate

```

### Why another tagging trait?

[](#why-another-tagging-trait)

At [Priblo](https://www.priblo.com) we couldn't find a suitable tagging trait for Laravel. Each one fell short for some reason or another. Mainly in the performance department. Tags are an important part of Priblo and we needed to get them right. Opting for the [Decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) we put an emphasis on caching and performance. We considered contributing to other projects, but none were in line with our design philosophy. So here it is our implementation, hoping it will be useful to someone else.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~47 days

Total

6

Last Release

2795d ago

PHP version history (2 changes)v1.0.0-betaPHP &gt;=7.0.0

v1.0.0-beta.2PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cea619fe9ba025fd94836d48a3edcbbef60baa38a810048f39f8ef382c780c5?d=identicon)[0plus1](/maintainers/0plus1)

---

Top Contributors

[![0plus1](https://avatars.githubusercontent.com/u/420815?v=4)](https://github.com/0plus1 "0plus1 (29 commits)")

---

Tags

eloquentlaraveltaggingtagslaraveleloquenttagstagtagginghashtaghashtags

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/priblo-laravel-has-tags/health.svg)

```
[![Health](https://phpackages.com/badges/priblo-laravel-has-tags/health.svg)](https://phpackages.com/packages/priblo-laravel-has-tags)
```

###  Alternatives

[rtconner/laravel-tagging

Use PHP traits to extend Laravel Eloquent Models to allow Tags. Models can be marked as Taggable.

8833.1M14](/packages/rtconner-laravel-tagging)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
