Weave Code
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 Package

spatie/laravel-tags

Add flexible tagging to Laravel Eloquent models with the HasTags trait. Create, attach, detach, and query tags with ease, with built-in support for tag types, translations, and sorting—ideal for organizing content across your app.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Laravel-native: Seamlessly integrates with Eloquent models, leveraging Laravel’s ORM and query builder for tagging functionality.
    • Modular Design: Lightweight (~100KB) with minimal core dependencies (only spatie/eloquent-sortable for ordering).
    • Batteries-Included: Supports tag types, translations, sorting, and scoped queries out-of-the-box, reducing custom development.
    • Database Agnostic: Works with MySQL, PostgreSQL, and SQLite (via JSON fields for translations).
    • Future-Proof: Actively maintained (last release: 2026-06-20), with support for Laravel 13 and PHP 8+.
  • Cons:

    • Schema Lock-in: Requires tags and taggables tables, which may conflict with existing schemas or multi-tenant setups.
    • JSON Dependency: Relies on database JSON support for translations (PostgreSQL requires JSONB; MySQL/SQLite use JSON).
    • No GraphQL/REST API: Primarily a database-layer solution; API integration (e.g., filtering by tags) must be built separately.

Integration Feasibility

  • Low Risk:
    • Zero Config: Auto-registers via Laravel’s service provider; no manual bootstrapping.
    • Trait-Based: Add HasTags to any Eloquent model in <5 minutes.
    • Backward Compatibility: Supports Laravel 8–13 and PHP 8+, with minimal breaking changes.
  • Potential Challenges:
    • Migration Complexity: If using an existing tagging system (e.g., many-to-many with pivot tables), data migration may require custom logic.
    • Performance: Tag queries (e.g., withAnyTags) use subqueries, which could impact large datasets. Indexing taggable_id and tag_id is critical.

Technical Risk

Risk Area Assessment Mitigation Strategy
Database Compatibility PostgreSQL requires JSONB; MySQL/SQLite use JSON. Test translations in target DB early; consider spatie/laravel-translatable if translations are complex.
Schema Conflicts Default table names (tags, taggables) may clash. Use --tag="tags-migrations" to customize table names in config/tags.php.
Query Performance Scoped queries (e.g., withAnyTags) may slow with >10K tags. Add indexes to taggables(tag_id, taggable_id); paginate results.
Multi-Tenancy No built-in tenant isolation. Extend Tag model to include tenant_id or use Laravel’s GlobalScope.
Caching No built-in caching for tag lookups. Cache frequent queries (e.g., Tag::all()) with Laravel’s cache or Redis.

Key Questions for Stakeholders

  1. Tagging Scale:

    • How many tags/models will this handle? (e.g., 10K vs. 1M+)
    • Follow-up: Will we need denormalized tag counts (e.g., tag_models_count) for performance?
  2. Localization:

    • Are translations required? If so, which locales?
    • Follow-up: Should we use spatie/laravel-translatable for complex translation workflows?
  3. Tag Types:

    • Do we need hierarchical tags (e.g., categories/subcategories)?
    • Follow-up: Consider spatie/laravel-activitylog for tag history if auditing is needed.
  4. API Exposure:

    • Will tags be filtered in APIs? If so, how will we structure endpoints?
    • Follow-up: Example: /articles?tags[]=php&tags[]=laravel
  5. Migration Path:

    • Are we replacing an existing tagging system? If yes, what’s the data migration plan?
    • Follow-up: Need a script to map old tags to new Tag records.
  6. Analytics:

    • Do we need tag popularity metrics (e.g., "most used tags")?
    • Follow-up: Add a TagObserver to track usage.

Integration Approach

Stack Fit

  • Laravel Ecosystem:

    • Perfect Fit: Designed for Laravel’s Eloquent, Query Builder, and Service Container.
    • Complements Existing Packages:
      • spatie/laravel-permission: Tag-based role assignment.
      • spatie/laravel-activitylog: Audit tag changes.
      • spatie/laravel-searchable: Full-text search on tags.
    • Frontend Agnostic: Works with Livewire, Inertia.js, or APIs.
  • Non-Laravel Considerations:

    • Not for Symfony/Symfony: Requires Laravel’s Eloquent.
    • No Standalone PHP: Tightly coupled to Laravel’s DI container.

Migration Path

Step Action Tools/Commands
1. Pre-Integration Review existing tagging logic (if any). Database schema analysis, API contract review.
2. Setup Install package and publish migrations/config. composer require spatie/laravel-tags + php artisan vendor:publish --tag="tags-migrations"
3. Schema Adjustments Customize table names/config if needed. Edit config/tags.php.
4. Model Integration Add HasTags trait to target models (e.g., Article, Product). use Spatie\Tags\HasTags; in model files.
5. Data Migration Migrate existing tags to new schema (if applicable). Custom Artisan command or Eloquent seeder.
6. API/Query Layer Build tag-filtering endpoints (e.g., Article::withAnyTags(['php'])->get()). Laravel API Resources or custom controllers.
7. Frontend Integration Expose tagging UIs (e.g., tag input fields, tag clouds). Alpine.js/Livewire for dynamic tagging; Tailwind CSS for styling.
8. Testing Validate tag CRUD, translations, and scoped queries. PHPUnit + Pest; test edge cases (e.g., empty tags, special characters).

Compatibility

  • Database:

    • MySQL 5.7+: Uses JSON for translations.
    • PostgreSQL 12+: Uses JSONB (better performance).
    • SQLite 3.35+: JSON support required.
    • SQL Server: No native JSON support (workaround: use spatie/laravel-activitylog for text-based storage).
  • Laravel Versions:

    • Supported: 8.0–13.x (tested via CI).
    • Unsupported: Laravel <8.0 (PHP 7.x).
  • PHP Versions:

    • Supported: 8.0–8.4 (PHP 8.5 may need updates).
    • Unsupported: PHP 7.x.

Sequencing

  1. Phase 1: Core Integration (2–3 days)

    • Install package, set up migrations, add HasTags to pilot models.
    • Test basic tagging (attach/detach/sync).
  2. Phase 2: Advanced Features (1–2 days)

    • Implement tag types, translations, and sorting.
    • Add custom scopes (e.g., withAnyTagsOfType).
  3. Phase 3: API/Query Layer (3–5 days)

    • Build endpoints for tag filtering (e.g., /articles?tags=php).
    • Optimize queries with indexes.
  4. Phase 4: Frontend & UX (1–2 weeks)

    • Develop tag input components (e.g., autocomplete).
    • Style tag displays (e.g., badges, clouds).
  5. Phase 5: Monitoring & Scaling (Ongoing)

    • Add caching for tag lookups.
    • Monitor query performance (e.g., withAnyTags on large datasets).

Operational Impact

Maintenance

  • Pros:

    • Minimal Boilerplate: No need to maintain tagging logic manually.
    • Active Maintenance: Spatie responds to issues within 24–48 hours (based on GitHub activity).
    • MIT License: No vendor lock-in; can fork if needed.
  • Cons:

    • Dependency Updates: Must track `spatie/eloquent-sort
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony