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

ActiveLibrary

unisharp/laravel-taggable
=========================

Handle with independent tables or in on table

2.0.x-dev(8y ago)333MITPHPPHP ^7.0

Since Apr 13Pushed 8y ago5 watchersCompare

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

READMEChangelogDependencies (12)Versions (2)Used By (0)

Laravel Taggable
----------------

[](#laravel-taggable)

### Introduction

[](#introduction)

this api can handle tag in independent tables or use only one table

### Install Taggable

[](#install-taggable)

composer.json:

```
"require" : {
    "unisharp/laravel-taggable" : "dev-master"
},
"repositories": {
    "type": "git",
    "url": "https://github.com/UniSharp/laravel-taggable.git"
}
```

save it and then

```
composer update

```

### Configure Taggable

[](#configure-taggable)

- config/app.php

    - providers:

```
Unisharp\Taggable\TaggableServiceProvider::class,
```

### Introduction

[](#introduction-1)

- **IndependentTaggable**: it's use independent table to save your tag

    eg. if Product is exists, you can use commad to generate ProductTag Model
- **IndependentCategorizable**: it's can categorize for your model

#### What different between tag and category?

[](#what-different-between-tag-and-category)

Tag is a many to many relationship, a taggalble entity can tag many tags, and there're many entities can belong a tag. However, a entity can only belong one category, it's one to one relation, and there're many entities can belong a category.

### Generate Independent Tag Table

[](#generate-independent-tag-table)

I assume Product model already exists, and you want make this model be taggable. if you don't have any models, you can use following builtin command to generate it

```
php artisan make:model Product --migration
```

and use following command to generate tag table and model for your Product

```
php artisan taggable:independent_tag_table Product
```

You will see there's ProductTag model under `app/` folder

Now, add trait for your product model let it be taggable.

```
use Unisharp\Taggable\Traits\IndependentTaggable;

class Product extends Model
{
    use IndependentTaggable
}
```

### Use Independent Tag

[](#use-independent-tag)

- tag your Model

```
$product = Product::find(1);
$product->tag('new_tag'); // only string
$product->tag('tag1', 'tag2', 'tag3'); // multi string also work
$product->tag(['tag1', 'tag2']); // array is acceptable
```

- untag it

```
$product->untag('new_tag');
$product->untag('tag1', 'tag2', 'tag3');
$product->untag(['tag1', 'tag2']);
```

- get your tags

```
$product->tags // it will return ProductTag back

```

- list your entity which belong specified tag

```
$tag = ProductTag::find(1);
$tag->entities // it will return Products back
```

### Generate Independent Category

[](#generate-independent-category)

Just like independent tag, you can generate independent category migration by command.

```
php artisan taggable:independent_category_table Product

```

it will generate ProductCategory for Product

and you can add category trait for Product just like before.

```
use Unisharp\Taggable\Traits\IndependentIndependentCategorizable;

class Product extends Model
{
    use IndependentCategorizable;
}

```

### Use Independent Category

[](#use-independent-category)

- categorize your model

```
$product = Product::find(1);
$product->categorize('free'); // use string
$product->categorize(1); // use product_category id
```

- decategorize

```
$product->decategorize();
```

- list your model's category

```
$product->catetory // list its category, it return ProductCategory
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity44

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

3032d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/49773ea5050ec1d004a506cc1e11be08d6e87339120b5d223b8921e3f671153c?d=identicon)[g0110280](/maintainers/g0110280)

![](https://avatars.githubusercontent.com/u/181350?v=4)[Youchen Lee (isacl)](/maintainers/youchenlee)[@youchenlee](https://github.com/youchenlee)

---

Top Contributors

[![youchenlee](https://avatars.githubusercontent.com/u/181350?v=4)](https://github.com/youchenlee "youchenlee (5 commits)")

---

Tags

laraveltag

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)

PHPackages © 2026

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