Get related models for the current model. Commonly used for "similar products" sections.
You can install the package via composer:
composer require mmedia/laravel-collaborative-filtering
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.
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.