-
I came across this package today and I'm struggling to figure out exactly how to use it to achieve what I want. I'm aiming to develop a feature where I can recommend posts to users based on the content of the posts they've previously liked. |
Beta Was this translation helpful? Give feedback.
Answered by
umutphp
Sep 21, 2023
Replies: 1 comment 2 replies
-
Hi @Kyzegs , Many thanks for the question. Your case is very similiar to the Usecase 1 at README. So, for your case your Post model should as follows; <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Umutphp\LaravelModelRecommendation\InteractWithRecommendation;
use Umutphp\LaravelModelRecommendation\HasRecommendation;
class Post extends Model implements InteractWithRecommendation
{
use HasFactory, HasRecommendation;
public static function getRecommendationConfig() :array
{
return [
'like' => [
'recommendation_algorithm' => 'db_relation',
'recommendation_data_table' => 'likes',
'recommendation_data_table_filter' => [],
'recommendation_data_field' => 'post_id',
'recommendation_data_field_type' => self::class,
'recommendation_group_field' => 'user_id',
'recommendation_count' => 5
]
];
}
} And the function calls should be as follows; <?php
...
use App\Model\Post;
Post::generateRecommendations('like');
$post = Post::find(1);
$recommendations = $post->getRecommendations('like'); I hope it helps :) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
umutphp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Kyzegs ,
Many thanks for the question. Your case is very similiar to the Usecase 1 at README. So, for your case your Post model should as follows;