PHPackages                             shamilchoudhury/eloquent-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. shamilchoudhury/eloquent-tags

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

shamilchoudhury/eloquent-tags
=============================

A tagging package for Laravel Eloquent models

1.0.0(8y ago)2231PHPPHP &gt;=7.0.0

Since May 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/shamilchoudhury/eloquent-tags)[ Packagist](https://packagist.org/packages/shamilchoudhury/eloquent-tags)[ RSS](/packages/shamilchoudhury-eloquent-tags/feed)WikiDiscussions master Synced yesterday

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

Eloquent-Tags
=============

[](#eloquent-tags)

A tagging package for Laravel Eloquent models.

Requirements
------------

[](#requirements)

This package requires Laravel 5.3 or higher and PHP 7.0 or higher.

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

[](#installation)

1. Install the `shamilchoudhury/eloquent-tags` package via composer:

    ```
    $ composer require shamilchoudhury/eloquent-tags
    ```
2. Add the service provider to `providers` array in `config/app.php`:

    ```
    'providers' => [
        ...
        \Shamil\Tags\Providers\TagsServiceProvider::class,
    ],
    ```
3. Use artisan to run the migration to create the required tags tables.

    ```
    php artisan migrate
    ```

Setup your Models
-----------------

[](#setup-your-models)

To make a model taggable, use the Taggable trait:

```
use Shamil\Tags\Taggable;

class Lesson extends Model
{
    use Taggable;
}
```

Done. Now your model is "taggable"!

Usage
-----

[](#usage)

Tag your models with the `tag()` method:

```
// Pass in an array
$lesson->tag(['snow', 'linen']);

// or you can pass in a model
$lesson->tag(\Shamil\Tags\Models\Tag::where('name', 'snow')->first());

// or a collection
$lesson->tag(\Shamil\Tags\Models\Tag::whereIn('name', ['snow', 'linen'])->get());
```

The `tag()` method is additive, so you can easily add new tags to the existing ones:

```
$lesson->tag(['linen']); // lesson has one tag 'linen'

$lesson->tag(['snow', 'linen']); // lesson now has two tags: 'linen' and 'snow'

$lesson->tag(['navy']); // lesson has three tags
```

Tag names are normalized to avoid duplicate tags:

```
$lesson->tag(['snow', 'SNOW', 'sNoW']); // lesson will be tagged with 'snow' only once
```

You can easily grab tags associated with a model using their relationship:

```
$lesson = Lesson::find(1);

foreach($lesson->tags as $tag) {
    echo $tag->name . ' ' ;
    // or do other stuff
}
```

Since this is a direct relationship, you can easily order tags by their count:

```
$lesson = Lesson::find(1);

foreach($lesson->tags()->orderBy('count', 'desc')->get() as $tag) {
    echo $tag->name . ' ' ; // this will echo tags in decreasing order of their count
}
```

Convert all tags associated with a model to an array:

```
$lesson = Lesson::find(1);

echo implode(' &bull; ', $lesson->tags->pluck('name')->toArray()); // Seperate tags by bullet points
```

You can grab a model with specific tags using query scopes:

```
// withAnyTag()
$lesson = Lesson::withAnyTag(['linen', 'snow', 'navy']);
dd($lesson->get()); // take any lesson that is tagged with any of the provided tags

//withAllTags()
$lesson = Lesson::withAllTags(['yellowgreen', 'navy']);
dd($lesson->get()); // only take lessons that are tagged with all of the provided tags

//withoutTags()
$lesson = Lesson::withoutTags(['snow', 'linen']);
dd($lesson->get()); // only take lessons that are not tagged with all of the provided tags
```

You can delete all current tags and add new tags with `retag()` :

```
$lesson = Lesson::find(1);

$lesson->retag(['darkorange']);
// all existing tags are removed and model is tagged with the tags provided
// in other words, model is first detagged and then tagged with the new tags
```

You can remove tags with `untag()` :

```
$lesson->tag(['lightcoral', 'yellowgreen', 'navy']);

$lesson->untag(['lightcoral']);
// $lesson is now tagged with "yellowgreen" and "navy"
```

Simply use `untag()` to remove all tags:

```
$lesson = Lesson::find(1);

$lesson->untag(); // all tags are removed
dd($lesson->tags); // $lesson now has an empty collection of tags
```

You can grab tags based on their count using the orderable scopes:

```
$tags = \Shamil\Tags\Models\Tag::usedGte(2); // tags with count greater than or equal to 2
dd($tags->get()); // all tags that have been used twice or more

// Similarly you can use other scopes

$tags = \Shamil\Tags\Models\Tag::usedGt(2); // tags with count greater than 2

$tags = \Shamil\Tags\Models\Tag::usedLte(2); // tags with count less than or equal to 2

$tags = \Shamil\Tags\Models\Tag::usedLt(2); // tags with count less than 2
```

License
-------

[](#license)

Eloquent-tags is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

3276d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5602f1d958e7623a9b3f45ee754096a6a36bda7f3966b5e508d34f727f8c27f9?d=identicon)[shamilchoudhury](/maintainers/shamilchoudhury)

---

Tags

laravelpackagetagging

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shamilchoudhury-eloquent-tags/health.svg)

```
[![Health](https://phpackages.com/badges/shamilchoudhury-eloquent-tags/health.svg)](https://phpackages.com/packages/shamilchoudhury-eloquent-tags)
```

###  Alternatives

[cybercog/laravel-love

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

1.2k302.7k1](/packages/cybercog-laravel-love)[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)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[aglipanci/laravel-eloquent-case

Adds CASE statement support to Laravel Query Builder.

115157.2k](/packages/aglipanci-laravel-eloquent-case)

PHPackages © 2026

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