PHPackages                             botdigit/laravel-taxonomies - 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. [Database &amp; ORM](/categories/database)
4. /
5. botdigit/laravel-taxonomies

ActiveLibrary[Database &amp; ORM](/categories/database)

botdigit/laravel-taxonomies
===========================

Simple, nestable Terms &amp; Taxonomies (similar to WordPress) for Laravel ^ 7.0

1.0.1(6y ago)351MITPHPPHP ^7.0CI failing

Since May 13Pushed 6y agoCompare

[ Source](https://github.com/ucanbehack/laravel-taxonomies)[ Packagist](https://packagist.org/packages/botdigit/laravel-taxonomies)[ Docs](https://github.com/ucanbehack/laravel-taxonomies)[ RSS](/packages/botdigit-laravel-taxonomies/feed)WikiDiscussions master Synced 2d ago

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

Laravel Taxonomies
==================

[](#laravel-taxonomies)

Simple, nestable Terms &amp; Taxonomies (similar to WordPress) for Laravel 7.

Important Notice
----------------

[](#important-notice)

**This package is a work in progress**, please use with care and feel free to report any issues or ideas you may have!

We've transferred this package to a new owner and therefor updated the namespaces to **Botdigit\\Taxonomies**. The config file is now `config/lecturize.php`.

Installation
------------

[](#installation)

`composer require botdigit/laravel-taxonomies`

Require the package from your `composer.json` file

```
"require": {
    "botdigit/laravel-taxonomies": "dev-master"
}
```

and run `$ composer update` or both in one with `$ composer require botdigit/laravel-taxonomies`.

Next register the service provider and (optional) facade to your `config/app.php` file

```
'providers' => [
    // ...
    Cviebrock\EloquentSluggable\ServiceProvider::class,
    Botdigit\Taxonomies\TaxonomiesServiceProvider::class,
];
```

Configuration &amp; Migration
-----------------------------

[](#configuration--migration)

```
$ php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"
$ php artisan vendor:publish --provider="Botdigit\Taxonomies\TaxonomiesServiceProvider"
```

This will create a `config/sluggable.php`, a `config/lecturize.php` and a migration file, that you'll have to run like so:

```
$ php artisan migrate
```

Usage
-----

[](#usage)

First, add our `HasTaxonomies` trait to your model.

```

```

##### Add a Term

[](#add-a-term)

```
$model->addTerm('My Category', 'taxonomy')
```

##### Add multiple Terms

[](#add-multiple-terms)

```
$model->addTerm(['Add','Multiple','Categories'], 'taxonomy')
```

##### Add a Term with optional parent (taxonomy) &amp; order

[](#add-a-term-with-optional-parent-taxonomy--order)

```
$model->addTerm('My Category', 'taxonomy', 1, 2)
```

##### Get all Terms for a model by taxonomy

[](#get-all-terms-for-a-model-by-taxonomy)

```
$model->getTerms('taxonomy')
```

##### Get a specific Term for a model by (optional) taxonomy

[](#get-a-specific-term-for-a-model-by-optional-taxonomy)

```
$model->getTerm('My Category', 'taxonomy')
```

##### Convenience method for getTerm()

[](#convenience-method-for-getterm)

```
$model->hasTerm($term, 'taxonomy')
```

##### Remove a Term from model by (optional) taxonomy

[](#remove-a-term-from-model-by-optional-taxonomy)

```
$model->removeTerm($term, 'taxonomy')
```

##### Remove all Terms from model

[](#remove-all-terms-from-model)

```
$model->removeAllTerms()
```

##### Scope models with multiple Terms

[](#scope-models-with-multiple-terms)

```
$model = Model::withTerms($terms, 'taxonomy')->get();
```

##### Scope models with one Term

[](#scope-models-with-one-term)

```
$model = Model::withTerm($term, 'taxonomy')->get();
```

Example
-------

[](#example)

**Add categories to an Eloquent model**

```
$post = Post::find(1);

$post->addTerm('My First Category', 'category');
$post->addTerm(['Category Two', 'Category Three'], 'category');
```

First fo all, this snippet will create three entries in your `terms` table, if they don't already exist:

- My First Category
- Category Two
- Category Three

Then it will create three entries in your `taxonomies` table, relating the terms with the given taxonomy "category".

And last it will relate the entries from your `taxonomies` table with your model (in this example a "Post" model) in your `pivot` table. ` use Botdigit\Taxonomies\Models\Taxable; use Botdigit\Taxonomies\Models\Taxonomy; use Botdigit\Taxonomies\Models\Term;`

$terms = Taxonomy::where('taxonomy', 'tags')-&gt;with('term')-&gt;get();

**Why three tables?**

Imagine you have a Taxonomy called *post\_cat* and another one *product\_cat*, the first categorises your blog posts, the second the products in your online shop. Now you add a product to a category (a *term*) called *Shoes* using `$product->addTerm('Sheos', 'product_cat');`. Afterwards you want to blog about that product and add that post to a *post\_cat* called *Shoes* as well, using `$product->addTerm('Sheos', 'post_cat');`.

Normally you would have two entries now in your database, one like `['Sheos','product_cat']` and another `['Sheos','post_at']`. Oops, now you recognize you misspelled *Shoes*, now you would have to change it twice, for each Taxonomy.

So I wanted to keep my *Terms* unique throughout my app, which is why I separated them from the Taxonomies and simply related them.

License
-------

[](#license)

Licensed under [MIT license](http://opensource.org/licenses/MIT).

Author
------

[](#author)

**Handcrafted by [Tarun](https://botdigit.com) in India .**

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~0 days

Total

2

Last Release

2191d ago

### Community

Maintainers

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

---

Top Contributors

[![Tarun-developer](https://avatars.githubusercontent.com/u/28224590?v=4)](https://github.com/Tarun-developer "Tarun-developer (2 commits)")[![botdigit-official](https://avatars.githubusercontent.com/u/53152562?v=4)](https://github.com/botdigit-official "botdigit-official (1 commits)")

---

Tags

laravelmodeleloquentnestablecategoriestaxonomiesterms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/botdigit-laravel-taxonomies/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[lecturize/laravel-taxonomies

Simple, nestable Terms &amp; Taxonomies (similar to WordPress) for Laravel.

10310.5k](/packages/lecturize-laravel-taxonomies)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)

PHPackages © 2026

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