Search by

pharaonic / laravel-tags

Pharaonic

Polymorphic tags for Laravel Eloquent models: types, normalized names, aliases, merging, search and bulk operations, with database-enforced identity.

Package info

github.com/Pharaonic/laravel-tags

Documentation

pkg:composer/pharaonic/laravel-tags

Fund package maintenance!

MoamenEltouny

Buy Me A Coffee

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

13.0.0 2026-12-06 03:46 UTC

This package is auto-updated.

Last update: 2026-12-06 03:47:26 UTC


README

PHP Version : 8.3 | 8.4 | 8.5 | 8.6 Laravel Version : 13.x License Build
Source Packagist Version Packagist Downloads AI Ready: Laravel Boost

Tags for Eloquent models: typed, normalized and aliased, with one identity per name kept by the database.


Installation

composer require pharaonic/laravel-tags
php artisan migrate

The service provider is registered automatically, and migrate creates the tags, tag_names and taggables tables. Publish the configuration to rename the tables, change the key types, or turn off automatic tag creation:

php artisan vendor:publish --tag=tags-config

Usage

use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Tags\Concerns\HasTags;

class Post extends Model
{
    use HasTags;
}
$post->attachTags(['Laravel', 'PHP']);       // created when missing
$post->attachTag('php');                     // the same tag: names are normalized
$post->attachTag('Laravel', 'framework');    // another tag: a type of its own
$post->syncTags(['laravel', 'Pest']);        // ['attached' => ..., 'detached' => ..., 'updated' => ...]
$post->hasTag('LARAVEL');                    // true

Tag::findOrCreate('JavaScript')->addAlias('JS');
$post->attachTag('js');                      // the JavaScript tag

Post::withAllTags(['laravel', 'pest'])->get();
Tag::suggest('lar');                         // Laravel, Larastan, ...
$post->relatedModels(Tag::ANY_TYPE, true)->limit(5)->get();

Documentation

Full documentation: Laravel Tags Documentation.

Support & Security

See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.

License

MIT. See LICENSE.