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+.
slug, type, and parent_id. This change requires database migration and may affect code that relies on global slug uniqueness assumptions.slug, type, and parent_id columnsTo upgrade from v2.2.1 to v2.3.0:
composer update aliziodev/laravel-taxonomyThis change affects:
For complete upgrade information, please refer to the UPGRADE.md file.
lft, rgt, depth fields)rebuildNestedSet() methodmoveToParent() method for efficient node repositioningtaxonomy:rebuild-nested-set command for rebuilding nested set valuestaxonomy:install command with better error handling-- Added nested set fields to taxonomies table
ALTER TABLE taxonomies ADD COLUMN lft INTEGER;
ALTER TABLE taxonomies ADD COLUMN rgt INTEGER;
ALTER TABLE taxonomies ADD COLUMN depth INTEGER DEFAULT 0;
-- Added indexes for performance
CREATE INDEX idx_taxonomies_nested_set ON taxonomies(type, lft, rgt);
CREATE INDEX idx_taxonomies_parent ON taxonomies(parent_id);
getAncestors() - Get all parent nodesgetDescendants() - Get all child nodesgetSiblings() - Get nodes at same levelgetNestedTree() - Get complete tree structureisAncestorOf() - Check parent-child relationshipisDescendantOf() - Check child-parent relationship# Run the migration to add nested set fields
php artisan migrate
# Rebuild nested set values for existing data
php artisan taxonomy:rebuild-nested-set
# Rebuild specific taxonomy type
php artisan taxonomy:rebuild-nested-set category
# Force rebuild without confirmation
php artisan taxonomy:rebuild-nested-set --force
// Old way (v1.x)
$children = $taxonomy->children;
$ancestors = $this->getAncestorsRecursively($taxonomy);
// New way (v2.0)
$children = $taxonomy->getDescendants();
$ancestors = $taxonomy->getAncestors();
lft, rgt, depth fields)rebuildNestedSet() methodmoveToParent() method for efficient node repositioningtaxonomy:rebuild-nested-set command for rebuilding nested set valuestaxonomy:install command with better error handling-- Added nested set fields to taxonomies table
ALTER TABLE taxonomies ADD COLUMN lft INTEGER;
ALTER TABLE taxonomies ADD COLUMN rgt INTEGER;
ALTER TABLE taxonomies ADD COLUMN depth INTEGER DEFAULT 0;
-- Added indexes for performance
CREATE INDEX idx_taxonomies_nested_set ON taxonomies(type, lft, rgt);
CREATE INDEX idx_taxonomies_parent ON taxonomies(parent_id);
getAncestors() - Get all parent nodesgetDescendants() - Get all child nodesgetSiblings() - Get nodes at same levelgetNestedTree() - Get complete tree structureisAncestorOf() - Check parent-child relationshipisDescendantOf() - Check child-parent relationship# Run the migration to add nested set fields
php artisan migrate
# Rebuild nested set values for existing data
php artisan taxonomy:rebuild-nested-set
# Rebuild specific taxonomy type
php artisan taxonomy:rebuild-nested-set category
# Force rebuild without confirmation
php artisan taxonomy:rebuild-nested-set --force
// Old way (v1.x)
$children = $taxonomy->children;
$ancestors = $this->getAncestorsRecursively($taxonomy);
// New way (v2.0)
$children = $taxonomy->getDescendants();
$ancestors = $taxonomy->getAncestors();
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
lft, rgt, depth fields)rebuildNestedSet() methodmoveToParent() method for efficient node repositioningtaxonomy:rebuild-nested-set command for rebuilding nested set valuestaxonomy:install command with better error handling-- Added nested set fields to taxonomies table
ALTER TABLE taxonomies ADD COLUMN lft INTEGER;
ALTER TABLE taxonomies ADD COLUMN rgt INTEGER;
ALTER TABLE taxonomies ADD COLUMN depth INTEGER DEFAULT 0;
-- Added indexes for performance
CREATE INDEX idx_taxonomies_nested_set ON taxonomies(type, lft, rgt);
CREATE INDEX idx_taxonomies_parent ON taxonomies(parent_id);
getAncestors() - Get all parent nodesgetDescendants() - Get all child nodesgetSiblings() - Get nodes at same levelgetNestedTree() - Get complete tree structureisAncestorOf() - Check parent-child relationshipisDescendantOf() - Check child-parent relationship# Run the migration to add nested set fields
php artisan migrate
# Rebuild nested set values for existing data
php artisan taxonomy:rebuild-nested-set
# Rebuild specific taxonomy type
php artisan taxonomy:rebuild-nested-set category
# Force rebuild without confirmation
php artisan taxonomy:rebuild-nested-set --force
// Old way (v1.x)
$children = $taxonomy->children;
$ancestors = $this->getAncestorsRecursively($taxonomy);
// New way (v2.0)
$children = $taxonomy->getDescendants();
$ancestors = $taxonomy->getAncestors();
Laravel Taxonomy is a powerful and flexible package for managing taxonomies, categories, tags, and hierarchical terms in Laravel applications. It provides a robust solution for organizing content with features like metadata support, ordering capabilities, and efficient caching mechanisms.
This package is ideal for:
How can I help you explore Laravel packages today?