PHPackages                             ritechoice23/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. [Database &amp; ORM](/categories/database)
4. /
5. ritechoice23/laravel-taggable

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

ritechoice23/laravel-taggable
=============================

The most intuitive and powerful Laravel tagging package that just works. Add intelligent tag normalization, trending analytics, powerful queries, and bulletproof edge case handling with zero configuration required.

1.0.1(4mo ago)1329↓100%[2 PRs](https://github.com/ritechoice23/laravel-taggable/pulls)MITPHPPHP ^8.2CI passing

Since Nov 6Pushed 6d agoCompare

[ Source](https://github.com/ritechoice23/laravel-taggable)[ Packagist](https://packagist.org/packages/ritechoice23/laravel-taggable)[ Docs](https://github.com/ritechoice23/laravel-taggable)[ GitHub Sponsors](https://github.com/ritechoice23)[ RSS](/packages/ritechoice23-laravel-taggable/feed)WikiDiscussions master Synced today

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

Laravel Taggable - The Developer's Choice
=========================================

[](#laravel-taggable---the-developers-choice)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8b1d4a829db76bb715e636178c702a9f6150c7711937a42db3e25e65a26c2d8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269746563686f69636532332f6c61726176656c2d7461676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ritechoice23/laravel-taggable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8f3360addedfb8a09c782e73eb06c3ed4243469c56ffb188cf3f3ce83d218014/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7269746563686f69636532332f6c61726176656c2d7461676761626c652f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ritechoice23/laravel-taggable/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a5c71d1bdc749b93b578b086e7f8caece57e642de31ca9194a808cc5fef191b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7269746563686f69636532332f6c61726176656c2d7461676761626c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/ritechoice23/laravel-taggable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/0ad9733c4744b90ddca1107ff3233852c8ad6f4d54d81f93da5c2d5475bc1adb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7269746563686f69636532332f6c61726176656c2d7461676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ritechoice23/laravel-taggable)

**The most intuitive and powerful Laravel tagging package that just works.** Add `$post->tag('laravel')` to any model and get intelligent tag normalization, trending analytics, powerful queries, and bulletproof edge case handling - all with zero configuration required.

Why this package
----------------

[](#why-this-package)

### Popular Alternatives

[](#popular-alternatives)

- [rtconner/laravel-tagging](https://github.com/rtconner/laravel-tagging)
- [spatie/laravel-tags](https://github.com/spatie/laravel-tags)
- [cviebrock/eloquent-taggable](https://github.com/cviebrock/eloquent-taggable)

### What Makes It Unique

[](#what-makes-it-unique)

✅ **Trending Score Algorithm** - Configurable trending calculation (volume, recency, velocity, freshness weights)

✅ **Tag Analytics** - Built-in `getActivitySummary()`, growth rate tracking

✅ **Momentum Bonuses** - Reward tags with consistent daily/weekly activity

✅ **Meta Attributes** - Color, description, icon stored as JSON on tags

✅ **High Growth Detection** - `whereHighGrowth()` scope for discovering rising topics

✅ **Artisan Command** - `php artisan tags:calculate-trending`

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

[](#installation)

You can install the package via composer:

```
composer require ritechoice23/laravel-taggable
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="taggable-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="taggable-config"
```

The config file allows you to customize the trending score calculation:

```
return [
    'trending' => [
        'weights' => [
            'volume' => 0.25,
            'recency' => 0.30,
            'velocity' => 0.25,
            'freshness' => 0.20,
        ],
        'time_periods' => [
            'daily' => 1,
            'weekly' => 7,
            'monthly' => 30,
            'velocity_comparison' => 14,
        ],
        'scoring' => [
            'volume_normalization' => 50,
            'freshness_decay' => 2,
            'velocity_multiplier' => 50,
        ],
        'momentum_bonuses' => [
            'daily_activity' => 1.1,
            'weekly_threshold_40' => 1.15,
            'weekly_threshold_60' => 1.2,
        ],
    ],
];
```

Optionally, you can publish the views using

Usage
-----

[](#usage)

### Add the Trait to Your Model

[](#add-the-trait-to-your-model)

```
use Ritechoice23\Taggable\Traits\HasTags;

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

### Tagging Models

[](#tagging-models)

The package provides a clean, intuitive API for managing tags using natural method names:

```
$post = Post::find(1);

// Attach tags (accepts strings, IDs, or Tag models)
$post->tag('laravel');
$post->tag(['php', 'programming']);

// Detach tags
$post->untag('laravel');
$post->untag(['php', 'programming']);

// Detach all tags
$post->untagAll();

// Replace all existing tags (retag)
$post->retag(['laravel', 'php']);
```

### Checking Tags

[](#checking-tags)

```
// Check if model has a specific tag
if ($post->hasTag('laravel')) {
    // ...
}

// Check if model has any of the given tags
if ($post->hasAnyTag(['laravel', 'php'])) {
    // ...
}

// Check if model has all of the given tags
if ($post->hasAllTags(['laravel', 'php'])) {
    // ...
}
```

### Querying Tagged Models

[](#querying-tagged-models)

```
// Get posts with a specific tag
$laravelPosts = Post::withTag('laravel')->get();

// Get posts with any of the given tags
$phpPosts = Post::withAnyTag(['laravel', 'php'])->get();

// Get posts with all of the given tags
$taggedPosts = Post::withAllTags(['laravel', 'php'])->get();
```

#### Available Query Scopes

[](#available-query-scopes)

**For Tagged Models (using HasTags trait):**

- `withTag($tag)` - Get models with a specific tag (by name, slug, ID, or Tag model)
- `withAnyTag($tags)` - Get models with any of the given tags
- `withAllTags($tags)` - Get models with all of the given tags

**For Tag Model:**

- `wherePopular($limit)` - Get most popular tags ordered by usage count
- `whereTrending($limit)` - Get trending tags ordered by trending score
- `whereName($name)` - Search tags by name (supports partial match)
- `whereSlug($slug)` - Find tags by slug (exact match)
- `whereRecentlyActive($days)` - Get tags active within the specified number of days
- `whereHighGrowth($days)` - Get tags with high growth in the specified period

### Working with Tags

[](#working-with-tags)

```
use Ritechoice23\Taggable\Models\Tag;

// Create a tag
$tag = Tag::create([
    'name' => 'Laravel',
    'meta' => [
        'color' => '#FF2D20',
        'description' => 'A PHP framework for web artisans',
        'icon' => 'laravel-icon',
    ],
]);

// Or set meta values individually
$tag->setMeta('color', '#FF2D20');
$tag->setMeta('description', 'A PHP framework for web artisans');

// Get meta values
$color = $tag->getMeta('color');
$description = $tag->getMeta('description', 'No description');

// Check if meta key exists
if ($tag->hasMeta('color')) {
    // ...
}

// Remove a meta key
$tag->removeMeta('icon');

// Get popular tags (ordered by usage count)
$popularTags = Tag::wherePopular(10)->get();

// Get trending tags (ordered by trending score)
$trendingTags = Tag::whereTrending(10)->get();

// Search tags by name
$searchResults = Tag::whereName('laravel')->get();

// Find tags by slug
$tag = Tag::whereSlug('laravel')->first();

// Get recently active tags
$activeTags = Tag::whereRecentlyActive(7)->get(); // Active in last 7 days

// Get tags with high growth
$growingTags = Tag::whereHighGrowth(7)->get(); // Growing in last 7 days

// Calculate trending scores
Tag::calculateAllTrendingScores();

// Or calculate for a specific tag
$tag->calculateTrendingScore();

// Get tag activity summary
$summary = $tag->getActivitySummary();
// Returns: total_count, trending_score, daily_activity, weekly_activity,
// monthly_activity, weekly_growth_rate, last_activity

// Manual count management (usually handled automatically)
$tag->incrementCount();  // Increment usage count
$tag->decrementCount();  // Decrement usage count
$tag->updateCount();     // Recalculate count from actual usage

// Get activity metrics
$recentActivity = $tag->getRecentActivityCount(7);  // Count in last 7 days
$growthRate = $tag->getGrowthRate(7);              // Growth percentage
```

### Configurable Trending Scores

[](#configurable-trending-scores)

The trending score calculation is fully configurable. You can adjust weights, time periods, and bonuses to match your application's needs:

```
'trending' => [
    'weights' => [
        'volume' => 0.25,
        'recency' => 0.30,
        'velocity' => 0.25,
        'freshness' => 0.20,
    ],

    'time_periods' => [
        'daily' => 1,
        'weekly' => 7,
        'monthly' => 30,
        'velocity_comparison' => 14,
    ],

    'scoring' => [
        'volume_normalization' => 50,
        'freshness_decay' => 2,
        'velocity_multiplier' => 50,
    ],

    'momentum_bonuses' => [
        'daily_activity' => 1.1,
        'weekly_threshold_40' => 1.15,
        'weekly_threshold_60' => 1.2,
    ],
],
```

### Artisan Commands

[](#artisan-commands)

Calculate trending scores for all tags:

```
php artisan tags:calculate-trending
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

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

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Daramola Babatunde Ebenezer](https://github.com/ritechoice23)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

43

↑

FairBetter than 91% of packages

Maintenance88

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~0 days

Total

2

Last Release

135d ago

### Community

Maintainers

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

---

Top Contributors

[![ritechoice23](https://avatars.githubusercontent.com/u/62488893?v=4)](https://github.com/ritechoice23 "ritechoice23 (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravel-packagelaravel-packageslaravel-taggablelaravel-tagssearchlaravelmodeleloquenttraitmetadatacmstagstaggingbloganalyticsarticlespoststaxonomycontent managementRelationshipsnormalizationcategorizationpolymorphictrendingritechoice23

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  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.

471160.2k3](/packages/rinvex-laravel-categories)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17648.2k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

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