Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Tags

Laravel Tags Laravel Package

spatie/laravel-tags

spatie/laravel-tags adds taggable behavior to Laravel Eloquent models via the HasTags trait. It supports translating tags, multiple tag types, and sorting out of the box, with simple attach/detach helpers for managing tags.

View on GitHub
Deep Wiki
Context7

spatie/laravel-tags adds flexible taggable behaviour to any Laravel application. Simply apply the HasTags trait to an Eloquent model and you can attach, detach, and sync tags with a fluent API—tags are created automatically if they don't already exist, so there's no extra setup.

Go beyond basic tagging with batteries-included features:

  • Multiple tag types to group tags by context
  • Translatable tags for multilingual applications
  • Sorting capabilities to control tag order
  • Query scopes like withAnyTags() and withAllTags() for filtering models
  • Seamless Eloquent integration, including creating tags via model attributes
Frequently asked questions about Laravel Tags
How do I add taggable behaviour to an Eloquent model with spatie/laravel-tags?
Add the Spatie\Tags\HasTags trait to any Eloquent model and it immediately becomes taggable. You can then use attachTag, attachTags, detachTag and detachTags, and tags are created automatically if they do not already exist. Tags can also be passed directly in a create call, for example 'tags' => ['first tag', 'second tag'], which is handy when seeding content.
How do I install and configure spatie/laravel-tags in a Laravel app?
Run composer require spatie/laravel-tags, publish the package migration with the vendor:publish command shown in the docs, then run php artisan migrate. Publishing the config file is optional and only exposes a slugger callback, so the configuration surface is deliberately small. After that, add the HasTags trait to each model you want to make taggable.
Which Laravel and PHP versions does spatie/laravel-tags support?
The package is built for Laravel 8+ on PHP 8+ and relies on Eloquent and service provider auto-discovery. Its changelog tracks framework releases closely, adding Laravel 12 support in 4.9.2 and Laravel 13 support in 4.11.0, which suggests framework upgrades will not become a blocker. It is Laravel-only, so non-Laravel PHP services in a wider estate gain nothing from it.
How do I query Eloquent models by tag in Laravel?
The HasTags trait exposes the query scopes withAnyTags, withAllTags, withoutTags and withAnyTagsOfType. These let you match records carrying any of a set of tags, require every tag to be present, or exclude records by tag. A fix shipped in 4.12.0 reduces N+1 queries on the tag read path.
Does spatie/laravel-tags support multiple tag types?
Yes. Every attach and detach method accepts an optional type argument, so categories and topics can coexist in the same tables without collisions. Typed helpers such as syncTagsWithType and the withAnyTagsOfType query scope keep type-specific workflows clean and readable.
Can I translate tags into multiple languages with spatie/laravel-tags?
Tag translations are built in, so tag names can be stored per locale and read back through tagsTranslated(). This suits multilingual UIs where the same tag needs a different label per language. Combined with tag types, it covers most CMS-style categorisation needs without writing custom tables.
What database does spatie/laravel-tags require?
The README requires a database that supports json fields and MySQL-compatible functions. PostgreSQL support only arrived in 4.10.0 and SQLite is exercised mainly through the test suite, so if production runs Postgres or MariaDB, smoke-test the tag query scopes rather than assuming parity. Confirm your RDBMS and version before sign-off.
How do I migrate existing tags from a custom table to spatie/laravel-tags?
Plan a two-phase migration. Introduce the tags and taggables tables, seed the tag rows, then backfill by iterating existing records and calling syncTagsWithType or the publicly exposed syncTagIds in chunked jobs, and dual-write for a release cycle before cutting reads over. Seeding tags first and using syncTagIds avoids per-row tag creation on large datasets.
Is spatie/laravel-tags suitable for production use at scale?
For typical content and CMS workloads it is a solid fit, but note that taggables is a polymorphic morph pivot keyed on taggable_type and taggable_id, and tag filtering is a join-heavy pattern. It is not designed for tag-faceted search at very large scale, so validate expected query volume, and remember the published migration becomes your responsibility once it lands in your repo.
Is spatie/laravel-tags still maintained, and what are the alternatives?
It is actively maintained: the changelog tracks Laravel releases up to Laravel 13, the package has a long release history and substantial download volume, and the MIT license removes legal friction. The reported zero dependents is almost certainly a registry artifact and should be corroborated internally rather than trusted. The realistic alternatives are a bespoke polymorphic tagging implementation or a simple json column, so weigh tag types, translations and manual sorting against your actual requirements.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai