PHPackages                             jutia-dev/laravel-category - 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. jutia-dev/laravel-category

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

jutia-dev/laravel-category
==========================

Associate Laravel models to a category/categories

0.0.1-alpha(4y ago)00MITPHPPHP &gt;=7.3

Since Nov 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JutiaDev/laravel-category)[ Packagist](https://packagist.org/packages/jutia-dev/laravel-category)[ RSS](/packages/jutia-dev-laravel-category/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Assets
======

[](#assets)

`php artisan vendor:publish --provider="JutiaDev\Category\CategoryServiceProvider"`

Relationships
=============

[](#relationships)

- All models using the `hasCategories` trait will have access to the following relation `$model->categories` that will fetch all categories associated to this `$model`
- All models using the `hasCategory` trait will have access to the following relation `$model->category` that will fetch the category associated to this `$model`
- You can fetch all models associated to a `$category` through `$category->{$relationshipName}`, where `$relationshipName` will be deduced by default from the model class

    - e.g. `$relationshipName` from Product model will be products therefore you can access it with `$category->products`, you can get the relationName of a model with the helper function `deduce_relationship_name_from_model(\App\Models\Product::class)`
    - You can customize the relationshipName by adding this variable (`protected string $relationshipName = 'customProducts';`) on the model that is using the `hasCategories` or `hasCategory` trait

Migration
=========

[](#migration)

> When to re-run migrations of the category package using the `php artisan migrate_category:refresh`:

- Adding a new model that uses either `hasCategory` or `hasCategories` trait
- Changing the trait of a model that was using for example the `hasCategory` trait to `hasCategories` or the inverse
- Changing the value of `cascadeDelete` on one of the models that uses the `hasCategory` trait
- Removing either the `hasCategory` or `hasCategories` from a model that was using either one of them

### 1 - A note on the `cascadeDelete`

[](#1---a-note-on-the-cascadedelete)

- By default `cascadeDelete` will be false on the model that is using the `hasCategory` trait, therefore the foreign key will be set to null when the associated category is deleted. if you want the model to be deleted too then you'll need this variable on the model using the `hasCategory` trait: `protected bool $cascadeDelete = true;`

### 2 - Impact of re-running migrations

[](#2---impact-of-re-running-migrations)

- The Categorizable table will be created only if any eloquent model start using the `hasCategories` trait and the table does not exist already
- The Categorizable table will be deleted if no model is using the `hasCategories` trait and the table already exist
- if a model switches from the `hasCategories` to the `hasCategory` trait then a new column referencing the category id (foreign key) will be added to the model. however if the `Categorizable` table is not deleted (check above point) then data will remain in the `Categorizable` table
- If a model that was using the `hasCategories` trait no longer uses any of the category trait then the foreign key column referencing the category\_id will be deleted
- If a model that was using the `hasCategories` trait switchs to the `hasCategories` trait then the foreign key column referencing the category\_id will be deleted but all data will be migrated to the `categorizable` table that will be created if it does not exist already.

### 3 - what does `php artisan migrate_category:refresh`

[](#3---what-does-php-artisan-migrate_categoryrefresh)

> - php artisan migrate:refresh --path=/database/migrations/2021\_11\_13\_000001\_create\_categorizable\_table.php
> - php artisan migrate:refresh --path=/database/migrations/2021\_11\_13\_000002\_add\_categories\_foreign\_key\_to\_related\_models.php

Resources
=========

[](#resources)

-
-
-
-

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

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

1636d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/08ea6bb62904f5e5b05a7a021173df03022a0010d9eb6e09e9e385721dac687d?d=identicon)[jutia-dev](/maintainers/jutia-dev)

---

Top Contributors

[![JutiaDev](https://avatars.githubusercontent.com/u/94493137?v=4)](https://github.com/JutiaDev "JutiaDev (1 commits)")

---

Tags

categorieslaravelphp

### Embed Badge

![Health badge](/badges/jutia-dev-laravel-category/health.svg)

```
[![Health](https://phpackages.com/badges/jutia-dev-laravel-category/health.svg)](https://phpackages.com/packages/jutia-dev-laravel-category)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[eighty8/laravel-seeder

Versioned, environment-based Seeders in Laravel

1857.1k](/packages/eighty8-laravel-seeder)

PHPackages © 2026

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