PHPackages                             umutphp/laravel-model-recommendation - 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. umutphp/laravel-model-recommendation

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

umutphp/laravel-model-recommendation
====================================

A generic package to create recommendation for eloquent models

v0.4.0(11mo ago)661.1k10[2 issues](https://github.com/umutphp/laravel-model-recommendation/issues)MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3CI passing

Since May 28Pushed 11mo ago2 watchersCompare

[ Source](https://github.com/umutphp/laravel-model-recommendation)[ Packagist](https://packagist.org/packages/umutphp/laravel-model-recommendation)[ Docs](https://github.com/umutphp/laravel_model_recommendation)[ GitHub Sponsors](https://github.com/umutphp)[ RSS](/packages/umutphp-laravel-model-recommendation/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (7)Versions (35)Used By (0)

Generate Recommendation List For Eloquent models
================================================

[](#generate-recommendation-list-for-eloquent-models)

[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/29d62e304d65974ac13be2791b34cc63fa63fb3ffd6bf2ba1f8a4e715a352e69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f756d75747068702f6c61726176656c2d6d6f64656c2d7265636f6d6d656e646174696f6e)](https://camo.githubusercontent.com/29d62e304d65974ac13be2791b34cc63fa63fb3ffd6bf2ba1f8a4e715a352e69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f756d75747068702f6c61726176656c2d6d6f64656c2d7265636f6d6d656e646174696f6e) [![WOSPM Checker](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/wospm.yml/badge.svg)](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/wospm.yml) [![Codestyle Check](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/phpcs.yml/badge.svg)](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/phpcs.yml) [![Test In All PHP Versions](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/composer-install.yml/badge.svg)](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/composer-install.yml) [![Markdown Linter](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/mardown-lint.yml/badge.svg)](https://github.com/umutphp/laravel-model-recommendation/actions/workflows/mardown-lint.yml)

This package generates recommendation list for elequent models objects. It provides a simple API to work with to generate and list recommendations for a model.

[![Laravel Model Recommendation](./assets/images/logo.png)](./assets/images/logo.png)

- [Glosary](#glosary)
- [How To Install](#how-to-install)
    - [Requiring The Library](#requiring-the-library)
    - [Prepare The Database](#prepare-the-database)
    - [Add The Service Provider](#add-the-service-provider)
    - [Add The Trait And Interface To The Model](#add-the-trait-and-interface-to-the-model)
- [How To Use](#how-to-use)
    - [Algorithms](#algorithms)
        - [DB Relation](#db-relation)
        - [Similarity](#similarity)
    - [Use Case 1](#use-case-1)
    - [Use Case 2](#use-case-2)
    - [Use Case 3](#use-case-3)
    - [Use Case 4](#use-case-4)
    - [Use Case 5](#use-case-5)
    - [Use Case 6](#use-case-6)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Glosary
-------

[](#glosary)

- **Data Table**: The table that stores the occurance (mosprobably with the ID of the model) of the models. Please look at the use cases for the example tables.
- **Group Field**: The field of the table that defines the co-occurance of the models.
- **Data Field**: The field that identifies the models.

How To Install
--------------

[](#how-to-install)

### Requiring The Library

[](#requiring-the-library)

```
composer require "umutphp/laravel-model-recommendation"
```

### Prepare The Database

[](#prepare-the-database)

```
php artisan vendor:publish --provider="Umutphp\LaravelModelRecommendation\ModelRecommendationServiceProvider"
php artisan migrate
```

### Add The Service Provider

[](#add-the-service-provider)

Append the following line to the `providers` array in `config/app.php`;

```
Umutphp\LaravelModelRecommendation\ModelRecommendationServiceProvider::class,
```

### Add The Trait And Interface To The Model

[](#add-the-trait-and-interface-to-the-model)

Add `HasRecommendation` trait and `InteractWithRecommendation` interface to the class definition of the model. Please do not forget to implement the config function of the interface.

`getRecommendationConfig()`: It should returns a multi dimensional array as follows with correct values. The definition of values in inner arrays are;

- **recommendation\_algorithm**: The choice of method for generating recommendations. The choices are `db_relation` and `similarity` for now. Some of the other keys are mandatory according to the choice.
- **recommendation\_data\_table**: The name of the data table which is mandatory when `db_relation` algorithm is choosen.
- **recommendation\_data\_table\_filter**: The array of the filter values to be used in the query for fetching data from data table which is optional and can be used when `db_relation` algorithm is choosen. The array will contain fields and values as key-value pairs. Pass an array like `'product_id' => ['
