PHPackages                             kjmtrue/laravel-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. kjmtrue/laravel-tags

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

kjmtrue/laravel-tags
====================

Rinvex Tags is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.

v4.1.3(3y ago)0659↓100%MITPHP

Since Apr 8Pushed 3y agoCompare

[ Source](https://github.com/kjmtrue/laravel-tags)[ Packagist](https://packagist.org/packages/kjmtrue/laravel-tags)[ Docs](https://rinvex.com)[ RSS](/packages/kjmtrue-laravel-tags/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (8)Versions (26)Used By (0)

Rinvex Tags
===========

[](#rinvex-tags)

**Rinvex Tags** is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of **[Sluggable](https://github.com/spatie/laravel-sluggable)**, and **[Translatable](https://github.com/spatie/laravel-translatable)** models out of the box.

[![Packagist](https://camo.githubusercontent.com/578102fbb506ad89623e30b30592db5767f08f52e3085ef6ddff646e2652f27a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696e7665782f6c61726176656c2d746167732e7376673f6c6162656c3d5061636b6167697374267374796c653d666c61742d737175617265)](https://packagist.org/packages/rinvex/laravel-tags)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3180baa23edb2ea7c79be1997e8d3b29a26b0f12415c80c5d211148337d3293a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f72696e7665782f6c61726176656c2d746167732e7376673f6c6162656c3d5363727574696e697a6572267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/rinvex/laravel-tags/)[![Travis](https://camo.githubusercontent.com/9312410fad3f84294ce8f60b372511a12eca9cc094b56e56e3da75bfea366f95/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f72696e7665782f6c61726176656c2d746167732e7376673f6c6162656c3d5472617669734349267374796c653d666c61742d737175617265)](https://travis-ci.org/rinvex/laravel-tags)[![StyleCI](https://camo.githubusercontent.com/a7aa5b1646bbe61bfa54b663a984d2c0571081077ea442a151d5a88cfb40af11/68747470733a2f2f7374796c6563692e696f2f7265706f732f38373539373834332f736869656c64)](https://styleci.io/repos/87597843)[![License](https://camo.githubusercontent.com/fc62ce71a35525e927d9787886cdbdecb2a30fc7cff4201f32e99a61b3830bf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72696e7665782f6c61726176656c2d746167732e7376673f6c6162656c3d4c6963656e7365267374796c653d666c61742d737175617265)](https://github.com/rinvex/laravel-tags/blob/develop/LICENSE)

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

[](#installation)

1. Install the package via composer:

    ```
    composer require rinvex/laravel-tags
    ```
2. Publish resources (migrations and config files):

    ```
    php artisan rinvex:publish:tags
    ```
3. Execute migrations via the following command:

    ```
    php artisan rinvex:migrate:tags
    ```
4. Done!

Usage
-----

[](#usage)

To add tags support to your eloquent models simply use `\Rinvex\Tags\Traits\Taggable` trait.

### Manage your tags

[](#manage-your-tags)

Your tags are just normal [eloquent](https://laravel.com/docs/master/eloquent) models, so you can deal with it like so. There's few more methods added to tag models for your convenience, let's take a look:

```
// Create new tag by name
app('rinvex.tags.tag')->createByName('My New Tag');

// Create new tag by name, group, and translation
app('rinvex.tags.tag')->createByName('The very new tag', 'blog', 'en');

// Find first tag by name
app('rinvex.tags.tag')->firstByName('My New Tag');

// Find first tag by name, group, and translation
app('rinvex.tags.tag')->firstByName('وسم جديد', 'board', 'ar');

// Find tag(s) by name
app('rinvex.tags.tag')->findByName('My New Tag');

// Find tag(s) by name, group, and translation
app('rinvex.tags.tag')->findByName('وسم جديد', 'board', 'ar');

// Find multiple tags by names array
app('rinvex.tags.tag')->findByName(['Tag One', 'Tag Two']);

// Find multiple tags by delimited names (tag delimiter is customizable)
app('rinvex.tags.tag')->findByName('First Tag, Second Tag, Third Tag');

// Find tag(s) by name or create if not exists
app('rinvex.tags.tag')->findByNameOrCreate('My Brand New Tag');

// Find tag(s) by name, group, and translation or create if not exists
app('rinvex.tags.tag')->findByNameOrCreate(['My Brand New Tag 2', 'My Brand New Tag 3']);
```

> **Notes:**
>
> - **Rinvex Tags** extends and utilizes other awesome packages, to be translatable out of the box using [`spatie/laravel-translatable`](https://github.com/spatie/laravel-translatable), and for automatic Slugging it uses [`spatie/laravel-sluggable`](https://github.com/spatie/laravel-sluggable) packages. Them them out.
> - Both `findByName()` and `findByNameOrCreate()` methods accepts either one or more tags as their first argument, and always return a collection.

### Manage your taggable model

[](#manage-your-taggable-model)

The API is intutive and very straightfarwad, so let's give it a quick look:

```
// Get instance of your model
$post = new \App\Models\Post::find(1);

// Get attached tags collection
$post->tags;

// Get attached tags query builder
$post->tags();
```

You can attach tags in various ways:

```
// Single tag id
$post->attachTags(1);

// Multiple tag IDs array
$post->attachTags([1, 2, 5]);

// Multiple tag IDs collection
$post->attachTags(collect([1, 2, 5]));

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->attachTags($tagInstance);

// Single tag name (created if not exists)
$post->attachTags('A very new tag');

// Multiple delimited tag names (use existing, create not existing)
$post->attachTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array (use existing, create not existing)
$post->attachTags(['First Tag', 'Second Tag']);

// Multiple tag names collection (use existing, create not existing)
$post->attachTags(collect(['First Tag', 'Second Tag']));

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->attachTags($tagInstances);
```

> **Notes:**
>
> - The `attachTags()` method attach the given tags to the model without touching the currently attached tags, while there's the `syncTags()` method that can detach any records that's not in the given items, this method takes a second optional boolean parameter that's set detaching flag to `true` or `false`.
> - To detach model tags you can use the `detachTags()` method, which uses **exactly** the same signature as the `attachTags()` method, with additional feature of detaching all currently attached tags by passing null or nothing to that method as follows: `$post->detachTags();`.
> - You may have multiple tags with the same name and the same locale, in such case the first record found is used by default. This is intended by design to ensure a consistent behavior across all functionality whether you are attaching, detaching, or scoping model tags.

And as you may have expected, you can check if tags attached:

```
// Single tag id
$post->hasAnyTags(1);

// Multiple tag IDs array
$post->hasAnyTags([1, 2, 5]);

// Multiple tag IDs collection
$post->hasAnyTags(collect([1, 2, 5]));

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->hasAnyTags($tagInstance);

// Single tag name
$post->hasAnyTags('A very new tag');

// Multiple delimited tag names
$post->hasAnyTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array
$post->hasAnyTags(['First Tag', 'Second Tag']);

// Multiple tag names collection
$post->hasAnyTags(collect(['First Tag', 'Second Tag']));

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->hasAnyTags($tagInstances);
```

> **Notes:**
>
> - The `hasAnyTags()` method check if **ANY** of the given tags are attached to the model. It returns boolean `true` or `false` as a result.
> - Similarly the `hasAllTags()` method uses **exactly** the same signature as the `hasAnyTags()` method, but it behaves differently and performs a strict comparison to check if **ALL** of the given tags are attached.

### Advanced usage

[](#advanced-usage)

#### Generate tag slugs

[](#generate-tag-slugs)

**Rinvex Tags** auto generates slugs and auto detect and insert default translation for you if not provided, but you still can pass it explicitly through normal eloquent `create` method, as follows:

```
app('rinvex.tags.tag')->create(['name' => ['en' => 'My New Tag'], 'slug' => 'custom-tag-slug']);
```

> **Note:** Check **[Sluggable](https://github.com/spatie/laravel-sluggable)** package for further details.

#### Smart parameter detection

[](#smart-parameter-detection)

**Rinvex Tags** methods that accept list of tags are smart enough to handle almost all kinds of inputs as you've seen in the above examples. It will check input type and behave accordingly.

#### Retrieve all models attached to the tag

[](#retrieve-all-models-attached-to-the-tag)

You may encounter a situation where you need to get all models attached to certain tag, you do so with ease as follows:

```
$tag = app('rinvex.tags.tag')->find(1);
$tag->entries(\App\Models\Post::class)->get();
```

#### Query scopes

[](#query-scopes)

Yes, **Rinvex Tags** shipped with few awesome query scopes for your convenience, usage example:

```
// Single tag id
$post->withAnyTags(1)->get();

// Multiple tag IDs array
$post->withAnyTags([1, 2, 5])->get();

// Multiple tag IDs collection
$post->withAnyTags(collect([1, 2, 5]))->get();

// Single tag model instance
$tagInstance = app('rinvex.tags.tag')->first();
$post->withAnyTags($tagInstance)->get();

// Single tag name
$post->withAnyTags('A very new tag')->get();

// Multiple delimited tag names
$post->withAnyTags('First Tag, Second Tag, Third Tag');

// Multiple tag names array
$post->withAnyTags(['First Tag', 'Second Tag'])->get();

// Multiple tag names collection
$post->withAnyTags(collect(['First Tag', 'Second Tag']))->get();

// Multiple tag model instances
$tagInstances = app('rinvex.tags.tag')->whereIn('id', [1, 2, 5])->get();
$post->withAnyTags($tagInstances)->get();
```

> **Notes:**
>
> - The `withAnyTags()` scope finds posts with **ANY** attached tags of the given. It returns normally a query builder, so you can chain it or call `get()` method for example to execute and get results.
> - Similarly there's few other scopes like `withAllTags()` that finds posts with **ALL** attached tags of the given, `withoutTags()` which finds posts without **ANY** attached tags of the given, and lastly `withoutAnyTags()` which find posts without **ANY** attached tags at all. All scopes are created equal, with same signature, and returns query builder.

#### Tag translations

[](#tag-translations)

Manage tag translations with ease as follows:

```
$tag = app('rinvex.tags.tag')->find(1);

// Update name translations
$tag->setTranslation('name', 'en', 'New English Tag Name')->save();

// Alternatively you can use default eloquent update
$tag->update([
    'name' => [
        'en' => 'New Tag',
        'ar' => 'وسم جديد',
    ],
]);

// Get single tag translation
$tag->getTranslation('name', 'en');

// Get all tag translations
$tag->getTranslations('name');

// Get tag name in default locale
$tag->name;
```

> **Note:** Check **[Translatable](https://github.com/spatie/laravel-translatable)** package for further details.

Changelog
---------

[](#changelog)

Refer to the [Changelog](CHANGELOG.md) for a full history of the project.

Support
-------

[](#support)

The following support channels are available at your fingertips:

- [Chat on Slack](https://bit.ly/rinvex-slack)
- [Help on Email](mailto:help@rinvex.com)
- [Follow on Twitter](https://twitter.com/rinvex)

Contributing &amp; Protocols
----------------------------

[](#contributing--protocols)

Thank you for considering contributing to this project! The contribution guide can be found in [CONTRIBUTING.md](CONTRIBUTING.md).

Bug reports, feature requests, and pull requests are very welcome.

- [Versioning](CONTRIBUTING.md#versioning)
- [Pull Requests](CONTRIBUTING.md#pull-requests)
- [Coding Standards](CONTRIBUTING.md#coding-standards)
- [Feature Requests](CONTRIBUTING.md#feature-requests)
- [Git Flow](CONTRIBUTING.md#git-flow)

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within this project, please send an e-mail to [help@rinvex.com](help@rinvex.com). All security vulnerabilities will be promptly addressed.

About Rinvex
------------

[](#about-rinvex)

Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License
-------

[](#license)

This software is released under [The MIT License (MIT)](LICENSE).

(c) 2016-2020 Rinvex LLC, Some rights reserved.

###  Health Score

33

—

LowBetter than 76% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~86 days

Recently: every ~222 days

Total

24

Last Release

1284d ago

Major Versions

v0.0.5 → v1.0.02018-10-05

v1.0.1 → v2.0.02019-03-03

v2.1.1 → v3.0.02019-09-22

v3.0.3 → v4.0.02020-03-15

PHP version history (6 changes)v0.0.1PHP ^7.0.0

v0.0.4PHP ^7.1.3

v2.0.0PHP ^7.2.0

v4.0.0PHP ^7.4.0

v4.1.0PHP ^7.4.0|^7.3

v4.1.1PHP ^7.4.0|^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5085f22e5f4981e925a44ad4ac1e8a941f0559f2e12a0d2a0c1087e4d940d2b?d=identicon)[kimtrien](/maintainers/kimtrien)

---

Top Contributors

[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (245 commits)")[![kimtrien](https://avatars.githubusercontent.com/u/9027134?v=4)](https://github.com/kimtrien "kimtrien (4 commits)")

---

Tags

laravelmodeleloquentsortablesluggabletranslatabletagtaxonomyrinvexTaggablepolymorphic

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[rinvex/laravel-categories

Rinvex Categories is a polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.

470160.2k3](/packages/rinvex-laravel-categories)[rinvex/laravel-tenants

Rinvex Tenants is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.

823.4k10](/packages/rinvex-laravel-tenants)

PHPackages © 2026

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