PHPackages                             zaichaopan/taggable - 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. zaichaopan/taggable

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

zaichaopan/taggable
===================

A package to make eloquent model taggable

v0.1-beta(7y ago)11MITPHPPHP &gt;=7.1

Since Jun 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/zaichaopan/taggable)[ Packagist](https://packagist.org/packages/zaichaopan/taggable)[ RSS](/packages/zaichaopan-taggable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Taggable
========

[](#taggable)

This Package is used to make eloquent model taggable. It can be used in laravel 5.5 or higher.

Installation
------------

[](#installation)

```
composer require zaichaopan/taggable
```

Usage
-----

[](#usage)

- Add tags and taggables table

After you install the package, run migration command to add **tags** and **taggables** table

```
php artisan migrate
```

The schemas of these two tables

```
// tags table
Schema::create('tags', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name')->unique();
    $table->string('slug')->unique();
    $table->timestamps();
});
```

```
// taggables table
Schema::create('taggables', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('tag_id');
    $table->foreign('tag_id')->references('id')->on('tags');
    $table->morphs('taggable');
    $table->timestamps();
});
```

This packages also provides **Tag** and **Taggable** models.

```
// To add a create tag
use  Zaichaopan\Taggable\Models\Tag;

Tag::create(['name' => 'laravel']);

// To get all the tag names
$names = Tag::getNames();
```

**Note**:

Please make sure tag name is unique. After you create or update a tag, its slug value will be automatically added or updated based on its name value.

- Add **hasTags** trait to the model you want to tag.

Let's say you have **Activity** model and you can give it tag.

```
//
use Zaichaopan\Taggable\Traits\HasTags;

class Activity extends Model
{
    use HasTags;
}
```

The **hasTags** trait provides the following methods to the model which uses it

**tags**:

It is used to get all the tags of the model:

```
$tags = $activity->tags;
```

**tag**:

```
/**
 *
 * @param string|array ...$tagNames
 */
public function tag(...$tagNames): void
```

```
$activity->tag('outdoor');

// or
$activity->tag('outdoor', 'sports');

// or
$activity->tag(['outdoor', 'sports']);
```

**Note**:

The tag name provided must be valid (exists in the tags table). If a tag name is invalid, it will be ignored. If a tag has already been given to a model, it will not be given again.

**reTag**:

```
/**
 *
 * @param string|array ...$tagNames
 */
public function reTag(...$tagNames): void
```

It is used to update a model's tag. After calling this method on a model, all its old tags will be moved and only the new tag will remain. If the tag name provided is invalid, it will be ignored. If all the provided tag names are invalid, the model will not be retagged. It will still keep its old tags.

```
$activity->tag('outdoor');

// the tag of the activity will be sports
$activity->reTag('sports');

// or
$activity->reTag(['outdoor', 'sports']);
```

**unTag**:

```
/**
 *
 * @param string|array ...$tagNames
 */
public function unTag(...$tagNames): void
```

It is used to remove a tag or multiple tags from a model. If a given tag name is invalid, it will be ignore. If all the given tag names are invalid, none of the model's tags will be removed.

```
$activity->unTag('outdoor');

// or
$activity->unTag('outdoor', 'sports');

// or
$activity->unTag(['outdoor', 'sports']);
```

**unTagAll**:

```
public function unTagAll(): void
```

It is used to removed all the tags of the model.

```
$activity->unTagAll();
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

2877d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dfb2782ff22c81ce8095946983c3d437156ed09b132ec93727da68a14fa7db0?d=identicon)[zaichaopan](/maintainers/zaichaopan)

---

Top Contributors

[![zaichaopan](https://avatars.githubusercontent.com/u/16104572?v=4)](https://github.com/zaichaopan "zaichaopan (8 commits)")

---

Tags

laravelphptaglaraveltag

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zaichaopan-taggable/health.svg)

```
[![Health](https://phpackages.com/badges/zaichaopan-taggable/health.svg)](https://phpackages.com/packages/zaichaopan-taggable)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[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)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)

PHPackages © 2026

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