PHPackages                             vendocrat/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. vendocrat/laravel-taxonomies

Abandoned → [lecturize/laravel-taxonomies](/?search=lecturize%2Flaravel-taxonomies)Library[Database &amp; ORM](/categories/database)

vendocrat/laravel-taxonomies
============================

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

v1.0.5(4y ago)1037430[1 issues](https://github.com/AlexanderPoellmann/laravel-taxonomies/issues)MITPHPPHP ^7.4|^8.0

Since Aug 30Pushed 3y ago9 watchersCompare

[ Source](https://github.com/AlexanderPoellmann/laravel-taxonomies)[ Packagist](https://packagist.org/packages/vendocrat/laravel-taxonomies)[ Docs](https://github.com/Lecturize/Laravel-Taxonomies)[ RSS](/packages/vendocrat-laravel-taxonomies/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (9)Versions (12)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/f38f7f064b38bc3d0d7442d3c8a04fdea440441e5939a602ec63a98e39b83bb1/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d7461786f6e6f6d6965732f762f737461626c65)](https://packagist.org/packages/lecturize/laravel-taxonomies)[![Total Downloads](https://camo.githubusercontent.com/c8a1b7aab0cec5b80d4653a0b3f297abe1d015ab1fc75986304743247a7ed3ec/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d7461786f6e6f6d6965732f646f776e6c6f616473)](https://packagist.org/packages/lecturize/laravel-taxonomies)[![License](https://camo.githubusercontent.com/48a0046acac92d70ae376993e338c776f12cbcf17039268e3c210106cc676269/68747470733a2f2f706f7365722e707567782e6f72672f6c6563747572697a652f6c61726176656c2d7461786f6e6f6d6965732f6c6963656e7365)](https://packagist.org/packages/lecturize/laravel-taxonomies)

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

[](#laravel-taxonomies)

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

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

[](#installation)

Require the package from your `composer.json` file

```
"require": {
    "lecturize/laravel-taxonomies": "^1.2"
}
```

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

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

[](#configuration--migration)

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

This will publish a `config/sluggable.php`, a `config/lecturize.php` and some migration files, that you'll have to run:

```
$ php artisan migrate
```

For migrations to be properly published ensure that you have added the directory `database/migrations` to the classmap in your projects `composer.json`.

Usage
-----

[](#usage)

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

```

```

##### Add a Term

[](#add-a-term)

```
$model->addCategory('My Category', 'blog_category')
```

##### Add multiple Terms

[](#add-multiple-terms)

```
$model->addCategories(['Add','Multiple','Categories'], 'blog_category')
```

##### Add a Term with optional parent\_id (taxonomy-&gt;id) &amp; sort order

[](#add-a-term-with-optional-parent_id-taxonomy-id--sort-order)

```
$model->addCategory('My Category', 'blog_category', 1, 2)
```

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

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

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

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

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

```
$model->getCategory('My Category', 'blog_category')
```

##### See if model has a given category within given taxonomy

[](#see-if-model-has-a-given-category-within-given-taxonomy)

```
$model->hasCategory('My Category', 'blog_category')
```

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

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

```
$model->detachCategory('My Category', 'blog_category')
```

##### Remove (detach) all categories relations from model

[](#remove-detach-all-categories-relations-from-model)

```
$model->detachCategories()
```

##### Scope models with any of the given categories

[](#scope-models-with-any-of-the-given-categories)

```
$model = Model::categorizedIn(['Add','Multiple','Categories'], 'blog_category')->get();
```

##### Scope models with one category

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

```
$model = Model::categorized('My Category', 'blog_category')->get();
```

Helper functions
----------------

[](#helper-functions)

I've included a set of helper functions for your convenience, see `src/helpers.php`.

Custom taxonomy model
---------------------

[](#custom-taxonomy-model)

Make sure to create a custom `Taxonomy` model, that extends `Lecturize\Taxonomies\Models\Taxonomy`.

```
