PHPackages                             hamedov/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hamedov/laravel-taxonomies

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

hamedov/laravel-taxonomies
==========================

Assign categories, tags, etc, to eloquent models.

4.0.0(2y ago)41.4k2[1 PRs](https://github.com/hamedov93/laravel-taxonomies/pulls)MITPHPPHP ^8.1

Since Apr 2Pushed 1y ago3 watchersCompare

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

READMEChangelogDependencies (6)Versions (24)Used By (0)

Laravel taxonomies
==================

[](#laravel-taxonomies)

Assign categories, tags, types, etc to your models or any taxonomy that can be used to classify models.

Installation
============

[](#installation)

`composer require hamedov/laravel-taxonomies`

Publish config file
===================

[](#publish-config-file)

`php artisan vendor:publish --provider="Hamedov\Taxonomies\TaxonomyServiceProvider" --tag="config"`

Create taxonomies
=================

[](#create-taxonomies)

```
use Hamedov\Taxonomies\Models\Taxonomy;

// Create new category
$category = Taxonomy::create([
  'title' => 'Electronics', // The only required field
  'description' => 'Electronics category description',
  'font_icon' => 'fa-laptop', // Enables you to assign font icons to your taxonomies
  'type' => 'category',
  'parent_id' => null, // Allow for sub categories/taxonomies
]);

// Or create a new tag
$tag = Taxonomy::create([
  'title' => 'Php', // The only required field
  'type' => 'tag',
]);

// Create any custom taxonomy
$ticket_class = Taxonomy::create([
  'title' => 'Class A',
  'description' => '',
  'font_icon' => 'fa-ticket',
  'type' => 'ticket_class',
]);

```

Assign image icons to taxonomies
================================

[](#assign-image-icons-to-taxonomies)

- The package uses spatie/laravel-medialibrary to allow you to assign image icons to taxonomies.
- You can configure icons collection name and icon conversions in the config file, you can define as many conversions as you like.
- The icon collection is a single file collection. ```
    'icon_collection_name' => 'taxonomy_icons',
      'icon_conversions' => [
      	'medium' => [120, 120], // Width, Height
      'small' => [90, 90],
      ],

    ```
- Assign an image to taxonomy ```
    // You can pass any parameter that can be passed to addMedia method of medialibrary package
    $taxonomy->setIcon(request()->file('icon'));

    ```
- Refer to [Media library documentation](https://docs.spatie.be/laravel-medialibrary/v7/introduction) for more info.

Translate taxonomies
====================

[](#translate-taxonomies)

- You can also set translations for the `title` and `description` columns using spatie/laravel-translatable package.
- You database server must support json columns for translations to work.
- Refer to for more information on how to translate these fields.

Manage model taxonomies
=======================

[](#manage-model-taxonomies)

- To be able to assign taxonomies to any of your models, the model must use the `HasTaxonomies` trait.

    ```
    use Hamedov/Taxonomies/Traits/HasTaxonomies;

    class Post extends Model {
      use HasTaxonomies;

    }

    ```
- Assign taxonomies to models

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

    // Add taxonomy to post
    $post->addTaxonomy($taxonomy->id);

    // Or add many taxonomies at once
    $post->addTaxonomies([1, 2, 3]);

    // Set new taxonomies and remove existing
    // This will remove all post taxonomies of type category
    // And then adds the new specified taxonomies
    // To remove all old taxonomies of all types remove the second parameter
    $post->setTaxonomies([1, 2, 3], 'category');

    // Remove post taxonomy
    $post->removeTaxonomy($taxonomy_id = 1);

    // Remove post taxonomies of specific type
    $post->removeTaxonomies('tag', [5, 6, 7]);
    // Or remove all post tags
    $post->removeTaxonomies('tag');

    // Remove all post taxonomies
    $post->removeAllTaxonomies();

    // Get post taxonomies by type
    $categories = $post->taxonomies('category')->get();
    $tags = $post->taxonomies('tags')->get();

    // Or get all taxonomies at once
    $taxonomies = $post->taxonomies;

    ```
- Available scopes

    ```
    // Scope taxonomies with specific type
    Taxonomy::type('category')->get();

    // Scope entries with a specific taxonomy
    $taxonomy = Taxonomy::find(1);
    $posts = Post::hasTaxonomy($taxonomy->id)->get();

    // Scope entries which have any of the specified taxonomies
    $posts = Post::hasAnyTaxonomy([1, 2, 3])->get();

    ```

Query models related to specific taxonomy
=========================================

[](#query-models-related-to-specific-taxonomy)

```
// We can only get one type of taxable models at once
// This is a limitation of many to many polymorphic relationships
$taxonomy = Taxonomy::find(1);
$taxonomy_posts = $taxonomy->taxables('App\Post')->get();
$taxonomy_products = $taxonomy->taxables('App\Product')->get();

// To get all models at once, we can do something like this
$taxonomy->load('taxes', 'taxes.taxable');
foreach($taxonomy->taxes as $tax)
{
  // $tax->taxable here is the post or product or any thing else.
  dd($tax->taxable);
}

```

Query related entries in pivot table
====================================

[](#query-related-entries-in-pivot-table)

- You can query entries related to specific taxonomy in pivot table ```
    $taxonomy = Taxonomy::find(1);
    $pivot_entries = $taxonomy->taxes()->where([
      // Filter by taxonomy_id, taxable_id, taxable_type
    ])->get();

    ```
- You can also do the same from other model perspective ```
    $post = Post::find(1);
    $pivot_entries = $post->taxes()->where([
      // Filter by taxonomy_id, taxable_id, taxable_type
    ])->get();

    ```

License
=======

[](#license)

Released under the Mit license, see [LICENSE](https://github.com/hamedov93/laravel-taxonomies/blob/master/LICENSE)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% 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 ~59 days

Recently: every ~199 days

Total

22

Last Release

981d ago

Major Versions

0.1.0 → 1.0.02020-04-20

1.0.0 → 2.0.02020-11-24

2.2.1 → 3.0.02022-09-08

3.0.1 → 4.0.02023-09-04

PHP version history (5 changes)0.0.1PHP ^7.2

2.0.0PHP ^7.3

2.1.0PHP ^7.3|^8.0

3.0.0PHP ^8.0

4.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/82c37e59c90c4c4b24cdb4e1dc98084ea2acd19e8cc1e8f7e928af64d39c05f2?d=identicon)[hamedov](/maintainers/hamedov)

---

Top Contributors

[![hamedov93](https://avatars.githubusercontent.com/u/13410895?v=4)](https://github.com/hamedov93 "hamedov93 (5 commits)")[![ADdora](https://avatars.githubusercontent.com/u/33669608?v=4)](https://github.com/ADdora "ADdora (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelattributestagscategoriestaxonomies

### Embed Badge

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

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

###  Alternatives

[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)[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)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[fomvasss/laravel-meta-tags

A package to manage SEO (meta-tags, xml-fields, etc.)

3028.9k](/packages/fomvasss-laravel-meta-tags)

PHPackages © 2026

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