mmedia / laravel-collaborative-filtering
Simple trait to add collaborative filtering to your models
Requires
- php: ^7.4|^8.0
- illuminate/support: ^5.8.0|^6.0|^7.0|^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-12-05 17:22:38 UTC
README
Get related models for the current model. Commonly used for "similar products" sections.
Installation
You can install the package via composer:
composer require mmedia/laravel-collaborative-filtering
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.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email contact@mmediagroup.fr instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.