PHPackages                             hamedrajabpour/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hamedrajabpour/laravel-tags

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hamedrajabpour/laravel-tags
===========================

Add tags and taggable behaviour to your Laravel app

1.0.9(9mo ago)0808[1 PRs](https://github.com/hamedrajabpour/laravel-tags/pulls)MITPHPPHP ^8.0

Since Feb 28Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/hamedrajabpour/laravel-tags)[ Packagist](https://packagist.org/packages/hamedrajabpour/laravel-tags)[ RSS](/packages/hamedrajabpour-laravel-tags/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (12)Used By (0)

Add tags and taggable behaviour to a Laravel app
================================================

[](#add-tags-and-taggable-behaviour-to-a-laravel-app)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f6d05f4e27afbae0f67a2eddf8dfe05797ba47df909ab23d5e65c3332ec7f2bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d656472616a6162706f75722f6c61726176656c2d746167732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hamedrajabpour/laravel-tags)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/58adb6f225759cb41ac584dd8fd1b73ef1d43d02c5c34934b4431d4031d34180/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f68616d656472616a6162706f75722f6c61726176656c2d746167732f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/58adb6f225759cb41ac584dd8fd1b73ef1d43d02c5c34934b4431d4031d34180/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f68616d656472616a6162706f75722f6c61726176656c2d746167732f72756e2d74657374733f6c6162656c3d7465737473)[![Total Downloads](https://camo.githubusercontent.com/3bfade03b5624bec1e398fb408787fba862d08d21879287de5df0c07a111b76c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d656472616a6162706f75722f6c61726176656c2d746167732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hamedrajabpour/laravel-tags)

This package offers taggable behaviour for your models. After the package is installed the only thing you have to do is add the `HasTags` trait to an Eloquent model to make it taggable.

The Main Diffrence Between This Package &amp; Spatie that removed translation &amp; slug
========================================================================================

[](#the-main-diffrence-between-this-package--spatie-that-removed-translation--slug)

Here are some code examples:

```
// apply HasTags trait to a model
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class NewsItem extends Model
{
    use HasTags;

    // ...
}
```

```
// create a model with some tags
$newsItem = NewsItem::create([
   'name' => 'The Article Title',
   'tags' => ['first tag', 'second tag'], //tags will be created if they don't exist
]);

// attaching tags
$newsItem->attachTag('third tag');
$newsItem->attachTag('third tag','some_type');
$newsItem->attachTags(['fourth tag', 'fifth tag']);
$newsItem->attachTags(['fourth_tag','fifth_tag'],'some_type');

// detaching tags
$newsItem->detachTag('third tag');
$newsItem->detachTag('third tag','some_type');
$newsItem->detachTags(['fourth tag', 'fifth tag']);
$newsItem->detachTags(['fourth tag', 'fifth tag'],'some_type');

// get all tags of a model
$newsItem->tags;

// syncing tags
$newsItem->syncTags(['first tag', 'second tag']); // all other tags on this model will be detached

// syncing tags with a type
$newsItem->syncTagsWithType(['category 1', 'category 2'], 'categories');
$newsItem->syncTagsWithType(['topic 1', 'topic 2'], 'topics');

// retrieving tags with a type
$newsItem->tagsWithType('categories');
$newsItem->tagsWithType('topics');

// retrieving models that have any of the given tags
NewsItem::withAnyTags(['first tag', 'second tag'])->get();

// retrieve models that have all of the given tags
NewsItem::withAllTags(['first tag', 'second tag'])->get();

// retrieve models that don't have any of the given tags
NewsItem::withoutTags(['first tag', 'second tag'])->get();

// using tag types
$tag = Tag::findOrCreate('tag 1', 'my type');

// tags are sortable
$tag = Tag::findOrCreate('my tag');
$tag->order_column; //returns 1
$tag2 = Tag::findOrCreate('another tag');
$tag2->order_column; //returns 2

// manipulating the order of tags
$tag->swapOrder($anotherTag);
```

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

[](#requirements)

This package requires Laravel 8 or higher, PHP 8 or higher, and a database that supports `json` fields and MySQL compatible functions.

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

[](#installation)

You can install the package via composer:

```
composer require hamedrajabpour/laravel-tags
```

The package will automatically register itself.

You can publish the migration with:

```
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="tags-migrations"
```

After the migration has been published you can create the `tags` and `taggables` tables by running the migrations:

```
php artisan migrate
```

You can optionally publish the config file with:

```
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="tags-config"
```

Testing
-------

[](#testing)

1. Copy `phpunit.xml.dist` to `phpunit.xml` and fill in your database credentials.
2. Run `composer test`.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance57

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~58 days

Recently: every ~130 days

Total

10

Last Release

283d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/038a3b649ec934d9614ec015ceca53fef3ae1aaeb848df24647b1bd76caee4cd?d=identicon)[hamedrajabpour](/maintainers/hamedrajabpour)

---

Top Contributors

[![hamedrajabpour1](https://avatars.githubusercontent.com/u/47815775?v=4)](https://github.com/hamedrajabpour1 "hamedrajabpour1 (26 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-analytics

A Laravel package to retrieve Google Analytics data.

3.2k5.7M57](/packages/spatie-laravel-analytics)[spatie/laravel-schedule-monitor

Monitor scheduled tasks in a Laravel app

9815.7M9](/packages/spatie-laravel-schedule-monitor)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[outerweb/image-library

Store and link files to your models

1113.0k2](/packages/outerweb-image-library)[tapp/filament-form-builder

User facing form builder using Filament components

131.2k1](/packages/tapp-filament-form-builder)

PHPackages © 2026

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