- 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.