pharaonic / laravel-tags
Polymorphic tags for Laravel Eloquent models: types, normalized names, aliases, merging, search and bulk operations, with database-enforced identity.
13.0.0
2026-12-06 03:46 UTC
Requires
- php: >=8.3 <8.7
- illuminate/config: ^13.0
- illuminate/console: ^13.0
- illuminate/container: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/events: ^13.0
- illuminate/support: ^13.0
- illuminate/translation: ^13.0
- pharaonic/laravel-sluggable: ^13.4
- symfony/polyfill-intl-normalizer: ^1.26
Requires (Dev)
- laravel/pint: ^1.30.6
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0 || ^5.3.4
- pharaonic/laravel-translatable: ^13.3
- phpstan/phpstan: ^2.1.33
- phpunit/phpunit: ^12.5.8 || ^13.4.5
Suggests
- pharaonic/laravel-translatable: ^13.3, for tag names (and, with Laravel Sluggable, slugs) translated per locale.
Provides
None
Conflicts
None
Replaces
None
README
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.
