amranidev/laracombee
Composer 安装命令:
composer require amranidev/laracombee
包简介
Recommendation system for laravel
README 文档
README
Laracombee
Laracombee is a Laravel package for the Recombee recommendation API. It provides a simple Laravel-friendly interface for working with users, items, user-item interactions, and recommendations.
This package is useful for applications such as e-commerce platforms, media libraries, and marketplaces where personalized recommendations can improve engagement and retention.
What is Recombee?
Recombee is an AI-powered recommendation service with a REST API and SDKs for building personalized recommendation systems.
To learn more about how Recombee works, see the official documentation:
Requirements
- PHP 8.2 or later
- Laravel 10, 11, or 12
Installation
Install the package with Composer:
composer require amranidev/laracombee
Laravel package discovery will register the service provider automatically.
If you want to publish the configuration file, run:
php artisan vendor:publish --tag=laracombee-config
Then add your Recombee database ID and private token to config/laracombee.php.
Configuration
Set your default user and item models in config/laracombee.php:
'user' => \App\Models\User::class, 'item' => \App\Models\Book::class,
These classes are used by the package commands.
You can also configure:
protocol: the HTTP protocol used for requests. The default ishttp.timeout: the default request timeout in milliseconds. The default is2000.region: the Recombee region. The default iseu-west.
Defining Recombee Properties
Each model that should be synchronized with Recombee must define a static $laracombee property.
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; public static $laracombee = [ 'name' => 'string', 'age' => 'int', ]; }
Do the same for your item model.
Usage
Add a user
use App\Models\User; use Laracombee; $user = User::findOrFail($id); $request = Laracombee::addUser($user); Laracombee::send($request) ->then(function () { // Success. }) ->otherwise(function ($error) { // Handle the error. }) ->wait();
Add multiple users in a batch
use App\Models\User; use Laracombee; $users = User::findMany([1, 2, 3])->all(); $batch = Laracombee::addUsers($users); Laracombee::batch($batch)->wait();
Recommend items to a user
use App\Models\User; use Laracombee; $user = User::findOrFail($id); $recommendations = Laracombee::recommendTo($user, 10)->wait(); $itemIds = collect($recommendations['recomms']) ->pluck('id') ->all();
Unlike most other methods in the package, recommendation methods trigger the request immediately and return a promise directly.
Commands
Laracombee includes several Artisan commands for managing your Recombee schema and data.
Migrate properties
php artisan laracombee:migrate user php artisan laracombee:migrate item
These commands read the static $laracombee property from the configured model and create the corresponding Recombee properties.
Roll back properties
php artisan laracombee:rollback user php artisan laracombee:rollback item
Seed existing records
php artisan laracombee:seed user php artisan laracombee:seed item
You can also set a custom chunk size:
php artisan laracombee:seed user --chunk=250
Add or drop properties manually
php artisan laracombee:add email:string age:int --to=user php artisan laracombee:drop email age --from=user
Reset the Recombee database
php artisan laracombee:reset
This command permanently removes all Recombee data, including users, items, properties, ratings, detail views, purchases, bookmarks, and series data. Do not run it in production unless you explicitly intend to wipe the Recombee database.
Generate a custom Laracombee class
php artisan laracombee:new CustomLaracombee
This creates a new class in app/Laracombee.
Available Methods
Laracombee generally follows Recombee naming conventions.
Users
Laracombee::deleteUser($userId)Laracombee::mergeUsersWithId($targetUserId, $sourceUserId)Laracombee::listUsers($options = [])Laracombee::addUserProperty($property, $type)Laracombee::deleteUserProperty($property)Laracombee::setUserValues($userId, $fields)Laracombee::getUserValues($userId)
Items
Laracombee::deleteItem($itemId)Laracombee::listItems($options = [])Laracombee::addItemProperty($property, $type)Laracombee::deleteItemProperty($property)Laracombee::setItemValues($itemId, $fields)Laracombee::getItemValues($itemId)Laracombee::getItemPropertyInfo($propertyName)
User-item interactions
Laracombee::addDetailView($userId, $itemId, $options = [])Laracombee::deleteDetailView($userId, $itemId, $options = [])Laracombee::listItemDetailViews($itemId)Laracombee::listUserDetailViews($userId)Laracombee::addPurchase($userId, $itemId, $options = [])Laracombee::deletePurchase($userId, $itemId, $options = [])Laracombee::addRating($userId, $itemId, $rating, $options = [])Laracombee::deleteRating($userId, $itemId, $options = [])Laracombee::listItemRatings($itemId)Laracombee::listUserRatings($userId)Laracombee::addCartAddition($userId, $itemId, $options = [])Laracombee::deleteCartAddition($userId, $itemId, $options = [])Laracombee::addBookmark($userId, $itemId, $options = [])Laracombee::deleteBookmark($userId, $itemId, $options = [])Laracombee::setViewPortion($userId, $itemId, $portion, $options = [])Laracombee::deleteViewPortion($userId, $itemId, $options = [])Laracombee::listItemViewPortions($itemId)Laracombee::listUserViewPortions($userId)
Recommendations
Laracombee::recommendItemsToUser($userId, $limit, $options = [])Laracombee::recommendUsersToUser($userId, $limit, $options = [])Laracombee::recommendTo($user, $limit = 10, $options = [])
Series
Laracombee::addSeries($seriesId)Laracombee::insertToSeries($seriesId, $itemType, $itemId, $time)Laracombee::removeFromSeries($seriesId, $itemType, $itemId, $time)Laracombee::deleteSeries($seriesId)Laracombee::listSeries()Laracombee::listSeriesItems($seriesId)
Utility
Laracombee::batch($requests)Laracombee::send($request)Laracombee::resetDatabase()
Extending the Package
If you want to tailor the behavior of the package, you can extend AbstractRecombee and implement your own send() method.
<?php namespace Acme\MyRecombee; use Amranidev\Laracombee\AbstractRecombee; use Recombee\RecommApi\Requests\Request; class MyRecombee extends AbstractRecombee { public function __construct() { parent::__construct( config('laracombee.database'), config('laracombee.token'), [ 'timeout' => config('laracombee.timeout'), 'region' => config('laracombee.region'), 'protocol' => config('laracombee.protocol'), ] ); } public function send(Request $request) { return $this->client->send($request); } }
This is useful if you want to customize error handling, request flow, or database targeting.
Multiple Recombee Databases
You can create additional Laracombee-style classes if you need to work with multiple Recombee databases from the same application.
The built-in generator can help you scaffold those classes:
php artisan laracombee:new ReportingLaracombee
Contributing
Thank you for considering contributing to the project. Please read the contribution guide.
License
This package is open-sourced software licensed under the MIT license.
amranidev/laracombee 适用场景与选型建议
amranidev/laracombee 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38.92k 次下载、GitHub Stars 达 115, 最近一次更新时间为 2018 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「recommendation system」 「recombee」 「laravel and recombee」 「laravel with recombee」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amranidev/laracombee 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amranidev/laracombee 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amranidev/laracombee 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Logging for PHP 5.3
Laravel 5.3+ integration for the Easyrec package.
ActionML Harness API PHP Client
Alfabank REST API integration
World class recommendation engine brought to Laravel
AI-Powered Product Recommendations using ChromaDB Vector Database for Magento 2
统计信息
- 总下载量: 38.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 115
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-03