Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: umutphp/laravel-model-recommendation
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.1
Choose a base ref
...
head repository: umutphp/laravel-model-recommendation
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 12 commits
  • 4 files changed
  • 3 contributors

Commits on Feb 4, 2024

  1. fix the generated wrong source_id value in the recommendations table

    Xoshbin committed Feb 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c16a57a View commit details
  2. Merge pull request #30 from Xoshbin/fix_wrong_source_id

    fix the generated wrong source_id value in the recommendations table
    umutphp authored Feb 4, 2024
    Copy the full SHA
    2a19d38 View commit details
  3. Fix the tests

    umutphp committed Feb 4, 2024
    Copy the full SHA
    0019948 View commit details

Commits on Aug 6, 2024

  1. Update composer.json

    Upgrade contracts and collections packages
    umutphp authored Aug 6, 2024
    Copy the full SHA
    a52400a View commit details
  2. Merge pull request #33 from umutphp/32-adding-support-for-laravel-11

    Add Laravel 11 Support
    umutphp authored Aug 6, 2024
    Copy the full SHA
    821252e View commit details
  3. Update README.md

    Fix typo
    umutphp authored Aug 6, 2024
    Copy the full SHA
    2672051 View commit details
  4. Merge pull request #34 from umutphp/umutphp-patch-1

    Update README.md
    umutphp authored Aug 6, 2024
    Copy the full SHA
    fe22937 View commit details

Commits on Sep 4, 2024

  1. Create gadpp.yml

    umutphp authored Sep 4, 2024
    Copy the full SHA
    270a4a9 View commit details
  2. Merge pull request #35 from umutphp/umutphp-patch-2

    Create gadpp.yml
    umutphp authored Sep 4, 2024
    Copy the full SHA
    cca45c9 View commit details

Commits on Feb 5, 2025

  1. Update HasRecommendation.php

    Add support for additional operators
    JakeOcean authored Feb 5, 2025
    Copy the full SHA
    81e665b View commit details
  2. Update README.md

    Update readme with info about new Operators
    JakeOcean authored Feb 5, 2025
    Copy the full SHA
    76a3323 View commit details

Commits on Feb 7, 2025

  1. Merge pull request #37 from JakeOcean/feature/additional-operators

    Feature/additional operators
    umutphp authored Feb 7, 2025
    Copy the full SHA
    0905c15 View commit details
Showing with 48 additions and 8 deletions.
  1. +19 −0 .github/workflows/gadpp.yml
  2. +6 −3 README.md
  3. +2 −2 composer.json
  4. +21 −3 src/HasRecommendation.php
19 changes: 19 additions & 0 deletions .github/workflows/gadpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Update GitHub Profile Page
on: [push]

jobs:
gadpp_job:
runs-on: ubuntu-latest
name: Update GitHub Profile Page
steps:
- name: Checkout
uses: actions/checkout@v2
- name: GADPP
uses: umutphp/github-action-dynamic-profile-page@v4
id: gadpp
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-username: 'umutphp'
user-email: 'umutphp@gmail.com'
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ Add `HasRecommendation` trait and `InteractWithRecommendation` interface to the

* **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.
* **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' => ['<', '500']` for more advanced operators
* **recommendation_data_field**: The name of the data field which is mandatory when `db_relation` algorithm is choosen.
* **recommendation_data_field_type**: The model class of the data field which is optional and can be used when `db_relation` algorithm is choosen.
* **recommendation_group_field**: The name of the group field which is mandatory when `db_relation` algorithm is choosen.
@@ -107,12 +107,15 @@ class ModelName extends Model implements InteractWithRecommendation
'recommendation_algorithm' => 'db_relation',
'recommendation_data_table' => 'recommendation_data_table',
'recommendation_data_table_filter' => [
'field' => 'value'
'field' => 'value',
// array syntax supports: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'
'product_id' => ["NOT NULL"],
'cost' => ["<", "500"],
],
'recommendation_data_field' => 'recommendation_data_field',
'recommendation_data_field_type' => 'recommendation_data_field_type',
'recommendation_group_field' => 'recommendation_group_field',
'recommendation_count' => 5
'recommendation_count' => 5,
'recommendation_order' => 'desc'
]
];
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@
],
"require": {
"php": "^7.4|^8.0|^8.1|^8.2|^8.3",
"illuminate/collections": "^8.0|^9.0|^10.0",
"illuminate/contracts": "^8.0|^9.0|^10.0",
"illuminate/collections": "^8.0|^9.0|^10.0|^11.0",
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0",
"spatie/laravel-package-tools": "^1.4.3"
},
"require-dev": {
24 changes: 21 additions & 3 deletions src/HasRecommendation.php
Original file line number Diff line number Diff line change
@@ -79,7 +79,25 @@ public static function getData($config)

if (is_array($config['recommendation_data_table_filter'])) {
foreach ($config['recommendation_data_table_filter'] as $field => $value) {
$data = $data->where($field, $value);
if (is_array($value) && count($value) >= 1) {
$operator = strtoupper((string)$value[0]);
$filterValue = $value[1] ?? null;
if ($operator === 'NULL') {
$data = $data->whereNull($field);
} elseif ($operator === 'NOT NULL') {
$data = $data->whereNotNull($field);
} elseif ($operator === 'IN') {
$data = $data->whereIn($field, $filterValue);
} elseif ($operator === 'NOT IN') {
$data = $data->whereNotIn($field, $filterValue);
} elseif (in_array($operator, ['=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) {
$data = $data->where($field, $operator, $filterValue);
} else {
$data = $data->where($field, $value);
}
} else {
$data = $data->where($field, $value);
}
}
}

@@ -301,7 +319,7 @@ public static function calculateSimilarityMatrix($models, $config): array
public function getRecommendations($name)
{
$config = $this->getRecommendationConfig()[$name] ?? null;
$model=$config['recommendation_data_field_type']??self::class;
$model = $config['recommendation_data_field_type'] ?? self::class;

if ($config === null) {
return [];
@@ -313,7 +331,7 @@ public function getRecommendations($name)
->where('source_id', $this->id)
->get();


$return = $model::query()->whereIn('id', $recommendations->pluck('target_id'))->get();

$order = $config['recommendation_order'] ?? config('laravel_model_recommendation.recommendation_count');