PHPackages                             aliziodev/laravel-terms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aliziodev/laravel-terms

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

aliziodev/laravel-terms
=======================

Laravel Terms is a flexible and powerful package for managing taxonomies, categories, tags, and other hierarchical terms in Laravel applications.

v1.1.3(1y ago)013MITPHPPHP ^8.1

Since Feb 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aliziodev/laravel-terms)[ Packagist](https://packagist.org/packages/aliziodev/laravel-terms)[ GitHub Sponsors](https://github.com/sponsors/aliziodev)[ RSS](/packages/aliziodev-laravel-terms/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (6)Used By (0)

LARAVEL TERMS PACKAGE
=====================

[](#laravel-terms-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0e271eb30fec2c4bb7fae115699080e6b4865ee0302173a2f59b4e8b925cf0a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c697a696f6465762f6c61726176656c2d7465726d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![Total Downloads](https://camo.githubusercontent.com/856cd16f084ba2f35d21b1be650b23d8428f30b763deabba4605347b706aeb14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c697a696f6465762f6c61726176656c2d7465726d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![PHP Version](https://camo.githubusercontent.com/8409254808f0f606565d9ab4d4494431ec2f62913e52d7256bc846f3ec871800/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c697a696f6465762f6c61726176656c2d7465726d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![Laravel Version](https://camo.githubusercontent.com/c7a2745f822e87369dd1522e6b9a42ccc087be88d6350b28e7db2ea4928c5e18/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e782d7265643f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![Laravel Version](https://camo.githubusercontent.com/095f07b46a36ffda6a1e41286b12a0e7cee7048f7762565692d3661d08bd34fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e782d7265643f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![Laravel Version](https://camo.githubusercontent.com/b0ed3341bf03bc1527750f5897b2f21d0fd01815215e74be4d7b17fa534637bf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31312e782d7265643f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)[![Laravel Version](https://camo.githubusercontent.com/e2ab74c900c407c3d7b80cd3689bb5c8f2767230a906c7b2c1e6f0ff8da66157/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d7265643f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aliziodev/laravel-terms)

Laravel Terms 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:

- E-commerce category management
- Blog taxonomies
- Content organization
- Product attributes
- Dynamic navigation
- Any hierarchical data structure

KEY FEATURES
------------

[](#key-features)

- Hierarchical terms (parent-child)
- Metadata support (JSON)
- Term ordering
- Caching system
- Polymorphic relationships
- Multiple term types
- Bulk operations
- Advanced querying
- Tree structure
- Flat tree structure

INSTALLATION
------------

[](#installation)

```
# Install via composer
composer require aliziodev/laravel-terms

# Publish config & migrations
php artisan terms:install

# Run migrations
php artisan migrate
```

CONFIGURATION
-------------

[](#configuration)

```
// config/terms.php
return [
    'types' => [
        'category',
        'tag',
        'size',
        'color',
        'unit',
        'type',
        'brand',
        'model',
        'variant',
    ],
];
```

BASIC USAGE
-----------

[](#basic-usage)

### 1. Model Setup

[](#1-model-setup)

```
use Aliziodev\LaravelTerms\Traits\HasTerms;

class Post extends Model
{
    use HasTerms;
}
```

### 2. Basic Operations

[](#2-basic-operations)

```
// Create term
$term = Term::create([
    'name' => 'Electronics',
    'type' => 'category'
]);

// Attach terms
$post->attachTerms(['electronics', 'gadgets']);

// Sync terms
$post->syncTerms(['electronics', 'gadgets']);

// Detach terms
$post->detachTerms(['electronics']);

// Get terms by type
$categories = $post->getTermsByType('category');

// Get terms grouped
$terms = $post->getTermsByGroups(['category', 'tag']);
```

### 3. Tree Operations

[](#3-tree-operations)

```
// Get tree structure
Term::tree();
Term::treeFlat();

// Get ancestors & descendants
$term->getAncestors();
$term->getDescendants();

// Get computed attributes
$term->path;      // 'electronics/phones/iphone'
$term->depth;     // 2
$term->is_leaf;   // true/false
$term->is_root;   // true/false
```

### 4. Ordering

[](#4-ordering)

```
// Move term
$term->moveToStart();
$term->moveToEnd();
$term->moveBefore($otherTerm);
$term->moveAfter($otherTerm);
$term->moveToOrder(5);
```

### 5. Meta Data

[](#5-meta-data)

```
// Set meta
$term->setMeta(['icon' => 'phone']);

// Get meta
$term->getMeta('icon');

// Update meta
$term->updateMeta(['icon' => 'new-phone']);

// Remove meta
$term->removeMeta('icon');

// Update meta for type
Term::updateMetaForType('category', ['visible' => true]);
```

API ENDPOINTS
-------------

[](#api-endpoints)

```
# List & Filter
GET /terms
GET /terms?type=category
GET /terms?parent_id=1
GET /terms?root=true
GET /terms?leaf=true
GET /terms?search=keyword
GET /terms?tree=true
GET /terms?flat_tree=true

# CRUD
POST /terms
GET /terms/{id}
PUT /terms/{id}
DELETE /terms/{id}

# Tree Operations
GET /terms/{id}?tree=true
GET /terms/{id}?ancestors=true
GET /terms/{id}?descendants=true

# Move Operations
POST /terms/{id}/move
{
    "parent_id": 1,
    "position": "before|after|start|end",
    "target_id": 2,
    "order": 5
}

# Statistics
GET /terms/stats

# Search
GET /terms/search?keyword=phone&type=category
```

QUERY SCOPES
------------

[](#query-scopes)

```
Term::search('keyword');    // Search in name, slug, description
Term::type('category');     // Filter by type
Term::root();              // Get root terms
Term::leaf();              // Get leaf terms
```

BEST PRACTICES
--------------

[](#best-practices)

1. Validate inputs
2. Use transactions for complex operations
3. Cache term instances
4. Use eager loading for relationships
5. Limit hierarchy depth
6. Validate term types
7. Handle circular references
8. Sanitize metadata
9. Use bulk operations
10. Maintain order consistency

TROUBLESHOOTING
---------------

[](#troubleshooting)

1. Reset cache if data is inconsistent
2. Check for circular references in hierarchy
3. Validate term types
4. Check order sequence
5. Monitor query performance
6. Use eager loading
7. Optimize metadata queries
8. Handle soft deletes
9. Maintain indexes
10. Monitor cache usage

For more detailed information, please check the source code or create an issue in the repository.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alizio](https://github.com/aliziodev)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance44

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

5

Last Release

444d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7060c3b21de26ce345cac7925c6cf8c469da49a614b9292cf38f8eed1bf099c?d=identicon)[aliziodev](/maintainers/aliziodev)

---

Top Contributors

[![mu-hanz](https://avatars.githubusercontent.com/u/44943686?v=4)](https://github.com/mu-hanz "mu-hanz (11 commits)")

---

Tags

laraveltagscategoriestaxonomyhierarchicaltermslaravel-terms

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aliziodev-laravel-terms/health.svg)

```
[![Health](https://phpackages.com/badges/aliziodev-laravel-terms/health.svg)](https://phpackages.com/packages/aliziodev-laravel-terms)
```

###  Alternatives

[aliziodev/laravel-taxonomy

Laravel Taxonomy is a flexible and powerful package for managing taxonomies, categories, tags, and hierarchical structures in Laravel applications. Features nested-set support for optimal query performance on hierarchical data structures.

23318.4k](/packages/aliziodev-laravel-taxonomy)[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
