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 Taxonomy Laravel Package

aliziodev/laravel-taxonomy

Flexible Laravel package for managing taxonomies, categories, tags, and hierarchical trees. Includes nested-set support for fast hierarchy queries, metadata, bulk operations, caching, and custom taxonomy types. Compatible with Laravel 11+.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hierarchical Data Model: The package excels at managing nested structures (e.g., categories, tags, or product attributes) with nested-set support, which aligns well with Laravel’s Eloquent ORM and database-optimized tree traversal. This is ideal for applications requiring dynamic, multi-level taxonomies (e.g., e-commerce, CMS, or knowledge bases).
  • Polymorphic Relationships: Supports attaching taxonomies to any model via Laravel’s polymorphic relationships, reducing duplication and enabling reusable taxonomy logic across entities.
  • Metadata Flexibility: JSON-based metadata storage allows for schema-less extensions (e.g., custom fields like icon, color, or featured flags) without altering the core schema.
  • Composite Unique Slugs: Slugs are unique per taxonomy type (e.g., featured can exist for both Category and Tag), enabling cleaner URL structures and avoiding global conflicts.

Integration Feasibility

  • Laravel 11/12 Compatibility: Built for modern Laravel, leveraging features like enums, facades, and query scopes seamlessly. Minimal friction with existing Laravel applications.
  • Database Agnostic: Works with MySQL, PostgreSQL, SQLite, and others, though nested-set performance is best optimized for PostgreSQL (due to recursive CTEs).
  • Migration Path: Provides automated migrations and multi-tenant support, making it easy to adopt incrementally. The taxonomy:install Artisan command streamlines setup.
  • Caching Layer: Built-in caching for taxonomy trees and query results, reducing database load in high-traffic applications.

Technical Risk

  • Nested-Set Complexity: While efficient, nested-set implementations can be less intuitive for developers unfamiliar with tree algorithms (e.g., left/right values). Requires understanding of Materialized Path or Closure Table alternatives if needed.
  • Slug Uniqueness Changes: Version 2.3.0+ enforces type-specific slug uniqueness, which may break existing applications if slugs were previously global. Requires migration planning for upgrades.
  • Performance at Scale: For millions of taxonomies, nested-set queries may need index optimization or denormalization (e.g., caching tree structures in Redis).
  • Polymorphic Overhead: Excessive use of polymorphic relationships can bloat pivot tables. Monitor taxonomables table growth in large-scale apps.

Key Questions

  1. Hierarchy Depth: What’s the maximum depth of taxonomies expected? Deep hierarchies (e.g., >5 levels) may require query tuning or alternative tree strategies.
  2. Concurrency: Will taxonomies be frequently edited (e.g., drag-and-drop reordering)? Nested-set updates require database transactions to avoid race conditions.
  3. Multi-Tenancy: Is the app tenant-aware? The package supports tenant isolation via migration autoloading, but custom logic may be needed for shared taxonomies across tenants.
  4. Search Requirements: Does the app need full-text search on taxonomy names? The package provides basic search() but may require Algoritma or Scout integration for advanced use cases.
  5. Legacy Data: Are there existing hierarchical data structures (e.g., categories in a legacy DB)? A migration script may be needed to backfill nested-set values.
  6. Custom Validation: Are there business rules for taxonomy creation (e.g., "Categories must have parents")? The package supports events and observers for custom logic.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Designed for Laravel, with zero external dependencies beyond Laravel core. Integrates natively with:
    • Eloquent Models: Uses traits (HasTaxonomy) and query builders.
    • Laravel Events: Supports creating, updating, deleting hooks for taxonomies.
    • Laravel Caching: Leverages Laravel’s cache system for performance.
    • Laravel Testing: Provides testing utilities (e.g., TaxonomyTestCase).
  • PHP 8.2+ Features: Uses enums, named arguments, and attributes, ensuring modern PHP compatibility.
  • Frontend Agnostic: Works with any frontend (Blade, Vue, React, etc.) since it exposes taxonomies via API or direct DB access.

Migration Path

  1. Pilot Phase:
    • Install in a non-production environment and test with a subset of models (e.g., Product or Article).
    • Verify nested-set queries perform adequately (benchmark with DB::enableQueryLog()).
    • Test polymorphic relationships with edge cases (e.g., detaching all taxonomies).
  2. Incremental Rollout:
    • Start with flat taxonomies (e.g., tags) before introducing hierarchies.
    • Use feature flags to toggle taxonomy support per model.
  3. Data Migration:
    • For existing hierarchies, write a data seeder to populate nested-set values (left, right, depth).
    • Example:
      // Seed nested-set values for existing categories
      $categories = Category::all();
      $tree = new \Aliziodev\LaravelTaxonomy\Services\TreeBuilder($categories);
      $tree->build();
      
  4. Deprecation Strategy:
    • Gradually replace custom category logic with the package’s methods (e.g., swap category()->whereParentId() for withTaxonomyHierarchy()).

Compatibility

  • Database: Tested on MySQL 8.0+, PostgreSQL 13+, and SQLite 3.35+. For SQL Server, ensure left/right columns are BIGINT to avoid overflow.
  • Laravel Services: Compatible with:
    • Laravel Scout: Extend Taxonomy for search-as-you-type functionality.
    • Laravel Nova/Vue: Add taxonomy pickers to admin panels.
    • Laravel Sanctum/Passport: Secure taxonomy endpoints if exposing via API.
  • Third-Party Packages:
    • Spatie Media Library: Attach taxonomies to media items.
    • Backpack/Crude: Integrate taxonomy pickers into admin interfaces.

Sequencing

  1. Setup:
    • Publish config/migrations: php artisan taxonomy:install.
    • Configure config/taxonomy.php (e.g., disable autoload for multi-tenant).
  2. Model Integration:
    • Add HasTaxonomy trait to models needing taxonomies.
    • Example:
      use Aliziodev\LaravelTaxonomy\Traits\HasTaxonomy;
      
      class Product extends Model
      {
          use HasTaxonomy;
      }
      
  3. Data Population:
    • Seed initial taxonomies (e.g., Electronics, Books) via a seeder or migration.
  4. API/Query Layer:
    • Replace custom category queries with package methods (e.g., withTaxonomySlug()).
  5. Caching:
    • Enable caching for taxonomy trees in config/taxonomy.php:
      'cache' => [
          'enabled' => env('TAXONOMY_CACHE_ENABLED', true),
          'prefix' => 'taxonomy_',
      ],
      
  6. Monitoring:
    • Track taxonomables table growth and query performance with Laravel Debugbar.

Operational Impact

Maintenance

  • Package Updates: The package follows semantic versioning with a changelog. Upgrades from v2.x to v3.0 may require:
    • Database migrations (e.g., slug uniqueness changes).
    • API deprecations (check UPGRADE.md).
  • Customization:
    • Extend taxonomy types by publishing migrations and adding to config/taxonomy.php.
    • Override models by configuring 'model' in the config.
  • Debugging:
    • Use Taxonomy::debug() to inspect tree structures.
    • Enable query logging for nested-set performance issues:
      DB::enableQueryLog();
      $tree = Taxonomy::tree(TaxonomyType::Category);
      dd(DB::getQueryLog());
      

Support

  • Documentation: Comprehensive README and DeepWiki integration. Example snippets cover 90% of use cases.
  • Community: 243 stars and active GitHub issues suggest moderate community support. Open issues are resolved within 1–2 weeks.
  • Enterprise Support: For critical applications, consider:
    • Dedicated maintenance contract with the package author.
    • Internal documentation for custom extensions.

Scaling

  • Database Optimization:
    • Add indexes for type, slug, and parent_id:
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony