PHPackages                             mmedia/laravel-collaborative-filtering - 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. mmedia/laravel-collaborative-filtering

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

mmedia/laravel-collaborative-filtering
======================================

Simple trait to add collaborative filtering to your models

1.0.2(3y ago)3146MITPHPPHP ^7.4|^8.0

Since Jul 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/M-Media-Group/Laravel-Collaborative-Filtering)[ Packagist](https://packagist.org/packages/mmedia/laravel-collaborative-filtering)[ Docs](https://github.com/mmedia/laravel-collaborative-filtering)[ RSS](/packages/mmedia-laravel-collaborative-filtering/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Very short description of the package
=====================================

[](#very-short-description-of-the-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/557638d6514a310f71819398fa0fee127513fd21b04f984a7ef8284118b2c4c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6d656469612f6c61726176656c2d636f6c6c61626f7261746976652d66696c746572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mmedia/laravel-collaborative-filtering)[![Total Downloads](https://camo.githubusercontent.com/8a5aa07855f2a75def860d7468cb9db27239debaa8e66177aaa52e4243a07a1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6d656469612f6c61726176656c2d636f6c6c61626f7261746976652d66696c746572696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mmedia/laravel-collaborative-filtering)[![GitHub Actions](https://github.com/mmedia/laravel-collaborative-filtering/actions/workflows/main.yml/badge.svg)](https://github.com/mmedia/laravel-collaborative-filtering/actions/workflows/main.yml/badge.svg)

Get related models for the current model. Commonly used for "similar products" sections.

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

[](#installation)

You can install the package via composer:

```
composer require mmedia/laravel-collaborative-filtering
```

Usage
-----

[](#usage)

Imagine you have a model called `Product`, and each product has multiple `ProductCategory` records. You want to find products related to each other based on how many common categories they have (a.k.a using collaborative filtering). To do so, you can define a relationship in your `Product` model.

```
use MMedia\LaravelCollaborativeFiltering\HasCollaborativeFiltering;

class Product extends Model {

    use HasCollaborativeFiltering;

    public function related()
    {
        return $this->hasManyRelatedThrough(ProductCategory::class, 'category_id');
    }

    public function relatedThroughLikes()
    {
        return $this->hasManyRelatedThrough(ProductLikes::class, 'user_id');
    }

}
```

Based on the article from [arctype](https://arctype.com/blog/collaborative-filtering-tutorial/).

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [M Media](https://github.com/mmedia)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

Every ~66 days

Total

3

Last Release

1306d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30b6a50e70c3cb395a88a29d0eae972f46aa11c0e0aa5c6d4e14ea52012fa3f3?d=identicon)[mwargan](/maintainers/mwargan)

---

Top Contributors

[![mwargan](https://avatars.githubusercontent.com/u/13789481?v=4)](https://github.com/mwargan "mwargan (8 commits)")

---

Tags

mmedialaravel-collaborative-filtering

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mmedia-laravel-collaborative-filtering/health.svg)

```
[![Health](https://phpackages.com/badges/mmedia-laravel-collaborative-filtering/health.svg)](https://phpackages.com/packages/mmedia-laravel-collaborative-filtering)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M375](/packages/illuminate-redis)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

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