PHPackages                             sohrab-az/laravel-taxonomy - 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. sohrab-az/laravel-taxonomy

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

sohrab-az/laravel-taxonomy
==========================

A flexible taxonomy package for Laravel

1.0.0(2mo ago)02MITPHP

Since May 3Pushed 2mo agoCompare

[ Source](https://github.com/sohrab-az/laravel-taxonomy)[ Packagist](https://packagist.org/packages/sohrab-az/laravel-taxonomy)[ RSS](/packages/sohrab-az-laravel-taxonomy/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

📦 Laravel Taxonomy Package
==========================

[](#-laravel-taxonomy-package)

A flexible and powerful taxonomy system for Laravel supporting:

- Categories (hierarchical / multiple)
- Tags (flat / multiple)
- Brands (flat / single)
- Polymorphic relationships
- Nested set structure (tree support)
- Query builder &amp; manager layer

---

🚀 Features
----------

[](#-features)

- 🔗 Attach multiple taxonomies to any model
- 🌲 Hierarchical taxonomy support (nested set)
- ⚙️ Config-driven taxonomy types
- 🔍 Fluent query builder
- 🧠 Smart sync / attach / detach logic
- 🌍 Language-aware taxonomies
- 👤 Creator tracking (polymorphic)

---

📦 Installation
--------------

[](#-installation)

```
composer require sohrab-az/laravel-taxonomy
```

⚙️ Publish Config
-----------------

[](#️-publish-config)

```
php artisan vendor:publish --tag=taxonomy-config
```

🧾 Configuration
---------------

[](#-configuration)

config/taxonomy.php

```
return [
    'types' => [
        'category' => [
            'label' => 'Category',
            'is_multiple' => true,
            'is_hierarchical' => true,
        ],

        'tag' => [
            'label' => 'Tag',
            'is_multiple' => true,
            'is_hierarchical' => false,
        ],

        'brand' => [
            'label' => 'Brand',
            'is_multiple' => false,
            'is_hierarchical' => false,
        ],
    ],
];
```

🗄 Database Structure
--------------------

[](#-database-structure)

### taxonomies table

[](#taxonomies-table)

- id
- name
- slug
- type
- order
- parent\_id (nested set)
- \_lft, \_rgt (nested set)
- language\_id
- created\_by\_type
- created\_by\_id
- timestamps

### Pivot: taxonomyables

[](#pivot-taxonomyables)

Polymorphic relation table:

- taxonomy\_id
- taxonomyable\_id
- taxonomyable\_type
- timestamps

🧠 Usage
-------

[](#-usage)

Add trait to your model

```
use SohrabAzinfar\Taxonomy\Traits\HasTaxonomies;

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

🔗 Relationship
--------------

[](#-relationship)

```
$post->taxonomies();
```

✍️ Attach Taxonomies
--------------------

[](#️-attach-taxonomies)

```
$post->attachTaxonomy($taxonomyId);
$post->attachTaxonomy([1, 2, 3]);
```

❌ Detach Taxonomies
-------------------

[](#-detach-taxonomies)

```
$post->detachTaxonomy($taxonomyId);
$post->detachTaxonomyByType('tag');
```

🔄 Sync Taxonomies
-----------------

[](#-sync-taxonomies)

```
$post->syncTaxonomy([1, 2, 3]);
$post->syncTaxonomyByType('category', [1, 2]);
```

🔍 Query Builder
---------------

[](#-query-builder)

```
$post->taxonomy()
```

### Examples

[](#examples)

```
$post->taxonomy()
    ->type('category')
    ->language('en')
    ->get();
```

Filters
-------

[](#filters)

```
    ->whereSlug('laravel')
    ->whereInSlug(['php', 'laravel'])
    ->whereId(1)
    ->children()
    ->root()
```

Execution
---------

[](#execution)

```
    ->get()
    ->first()
    ->pluck('name')
    ->count()
    ->exists()
```

🧠 Taxonomy Manager
------------------

[](#-taxonomy-manager)

Internal service handling logic:

```
app(TaxonomyManager::class)
```

### Features:

[](#features)

- Type-aware syncing
- Handles multiple/single constraints
- Prevents duplicate attachments
- Grouped processing per taxonomy type

🧩 Taxonomy Type Helper
----------------------

[](#-taxonomy-type-helper)

```
TaxonomyType::get('category');
TaxonomyType::exists('tag');
TaxonomyType::isMultiple('brand');
TaxonomyType::isHierarchical('category');
```

🏗 Service Provider
------------------

[](#-service-provider)

Automatically registered via:

```
TaxonomyServiceProvider
```

### Provides:

[](#provides)

- Config merging
- Migration loading
- Config publishing

📌 Requirements
--------------

[](#-requirements)

- PHP 8+
- Laravel 10+
- kalnoy/nestedset

\##📄 License

```
MIT License
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance84

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

82d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54e2e41c158ddc0f29395d4c4e3b16d2e4ba8e0adcc8eca90f092c58d7fde315?d=identicon)[sohrab-az](/maintainers/sohrab-az)

---

Top Contributors

[![sohrab-az](https://avatars.githubusercontent.com/u/76838208?v=4)](https://github.com/sohrab-az "sohrab-az (4 commits)")

### Embed Badge

![Health badge](/badges/sohrab-az-laravel-taxonomy/health.svg)

```
[![Health](https://phpackages.com/badges/sohrab-az-laravel-taxonomy/health.svg)](https://phpackages.com/packages/sohrab-az-laravel-taxonomy)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

27.6k172.1k9](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[riari/laravel-forum

A Laravel package providing a solid foundation for building discussion forums

65598.7k3](/packages/riari-laravel-forum)[biostate/filament-menu-builder

An Elegant Menu Builder for FilamentPHP

6528.1k2](/packages/biostate-filament-menu-builder)[wsmallnews/filament-nestedset

Filament nestedset tree builder powered by kalnoy/nestedset with Filament v4 and v5 support

197.8k19](/packages/wsmallnews-filament-nestedset)[novius/laravel-nova-order-nestedset-field

A Laravel Nova field that make your resources orderable

2393.1k2](/packages/novius-laravel-nova-order-nestedset-field)

PHPackages © 2026

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