Looking to hire Laravel developers? Try LaraJobs

laravel-tags maintained by pharaonic

Description
Polymorphic tags for Laravel Eloquent models: types, normalized names, aliases, merging, search and bulk operations, with database-enforced identity.
Last update
2026/12/06 04:46 (dev-develop)
License
Links
Downloads
1

Comments
comments powered by Disqus

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.