PHPackages                             foodieneers/laravel-tag - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. foodieneers/laravel-tag

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

foodieneers/laravel-tag
=======================

Laravel Package for Tagging Users

v1.0.3(3mo ago)023[1 PRs](https://github.com/foodieneers/laravel-tag/pulls)MITPHPPHP ^8.5CI passing

Since Mar 22Pushed 2mo agoCompare

[ Source](https://github.com/foodieneers/laravel-tag)[ Packagist](https://packagist.org/packages/foodieneers/laravel-tag)[ Docs](https://github.com/foodieneers/laravel-tag)[ RSS](/packages/foodieneers-laravel-tag/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (4)Dependencies (6)Versions (7)Used By (0)

Laravel Tag
===========

[](#laravel-tag)

[![Latest Version on Packagist](https://camo.githubusercontent.com/db4135d3b0c0423937694fd580270c4e848453d282af9fa7fc4922d356221981/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6f6469656e656572732f6c61726176656c2d7461672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/foodieneers/laravel-tag)[![GitHub Tests Action Status](https://camo.githubusercontent.com/24735497d1c246ceb5aaa407b8b0f2cd1ae89b678da2d6c8622ab666d94c4801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f666f6f6469656e656572732f6c61726176656c2d7461672f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/foodieneers/laravel-tag/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c2156cca1d3a8b37b8b616e2e325ad8648a8b8c672c78263d49f12e920fe9d07/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f666f6f6469656e656572732f6c61726176656c2d7461672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/foodieneers/laravel-tag/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/309c9a8a127873ca9e010705a20f19a4b655846ccd6d34e12b941e7240f9a70f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6f6469656e656572732f6c61726176656c2d7461672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/foodieneers/laravel-tag)

A Laravel package for tagging Eloquent models. Add the `HasTags` trait to any model and start tagging.

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

[](#installation)

```
composer require foodieneers/laravel-tag
```

Publish and run the migrations:

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

Add the `HasTags` trait to your model (e.g. `User`):

```
use Foodieneers\Tag\Traits\HasTags;
use Illuminate\Database\Eloquent\Model;

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

That's it. Your model can now be tagged.

---

API Reference
-------------

[](#api-reference)

### HasTags Trait

[](#hastags-trait)

Add to any Eloquent model that should be taggable.

#### `tags()` — BelongsToMany relation

[](#tags--belongstomany-relation)

Returns the tags relation. Use for attach, detach, sync, or querying.

```
$user->tags;                    // Collection of Tag models
$user->tags()->attach($tagId);  // Attach by ID
$user->tags()->detach($tagId);  // Detach by ID
$user->tags()->sync([1, 2, 3]); // Sync tag IDs
```

#### `tag(string $name): void`

[](#tagstring-name-void)

Attaches a tag by name. Creates the tag if it doesn't exist.

```
$user->tag('developer');
$user->tag('admin');
```

#### `detag(string $name): void`

[](#detagstring-name-void)

Removes a tag by name. No-op if the tag doesn't exist or isn't attached.

```
$user->detag('developer');
```

---

### Tag Model

[](#tag-model)

#### `Tag::name(string $name): Tag`

[](#tagnamestring-name-tag)

Get or create a tag by name. Creates with `description => 'Automatically generated'` when new.

```
$tag = Tag::name('laravel');
```

#### `Tag::setTaggableModel(string $class): void`

[](#tagsettaggablemodelstring-class-void)

Sets which model class is taggable. Called automatically by `HasTags::bootHasTags()`. Only needed if you use multiple taggable models or customize behavior.

```
Tag::setTaggableModel(User::class);
```

#### `$tag->tagged(): BelongsToMany`

[](#tag-tagged-belongstomany)

Returns the relation to models that have this tag.

```
$tag->tagged;           // Collection of tagged models (e.g. Users)
$tag->tagged()->get();  // Query builder
```

Pivot includes `created_at`.

#### `$tag->category(): BelongsTo`

[](#tag-category-belongsto)

Returns the optional tag category.

```
$tag->category;  // TagCategory or null
```

---

### TagCategory Model

[](#tagcategory-model)

#### `TagCategory::name(string $name): TagCategory`

[](#tagcategorynamestring-name-tagcategory)

Get or create a category by name. Creates with `description => 'Automatically generated'` when new.

```
$category = TagCategory::name('programming');
```

#### `$category->tags(): HasMany`

[](#category-tags-hasmany)

Returns tags in this category.

```
$category->tags;  // Collection of Tag models
```

---

Example
-------

[](#example)

```
// Tag a user
$user->tag('developer');
$user->tag('admin');

// List tags
$user->tags->pluck('name');  // ['developer', 'admin']

// Remove a tag
$user->detag('admin');

// Sync tags (replace all)
$user->tags()->sync([
    Tag::name('moderator')->id,
    Tag::name('reviewer')->id,
]);

// From a tag: get all tagged models
$tag = Tag::name('developer');
$tag->tagged;  // Users (or your taggable model) with this tag
```

---

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)

- [Azzarip](https://github.com/Azzarip)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance85

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88% 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

4

Last Release

96d ago

PHP version history (2 changes)v1.0.0PHP ^8.4

v1.0.2PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/552b5aa7ab775f5b73ebfd340bfbf922af893a120a4a97dc5abdf0ac7b116840?d=identicon)[azzarip](/maintainers/azzarip)

---

Top Contributors

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

---

Tags

laravellaravel-tagFoodieneers

### Embed Badge

![Health badge](/badges/foodieneers-laravel-tag/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k98.0M1.3k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[spatie/laravel-passkeys

Use passkeys in your Laravel app

470755.5k32](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.9M53](/packages/jeffgreco13-filament-breezy)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M153](/packages/spatie-laravel-health)

PHPackages © 2026

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