PHPackages                             janyksteenbeek/laravel-gorse - 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. [API Development](/categories/api)
4. /
5. janyksteenbeek/laravel-gorse

ActiveLibrary[API Development](/categories/api)

janyksteenbeek/laravel-gorse
============================

Laravel integration for Gorse recommendation engine

v0.2.12(1y ago)4921MITPHPPHP ^8.1

Since Mar 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/janyksteenbeek/laravel-gorse)[ Packagist](https://packagist.org/packages/janyksteenbeek/laravel-gorse)[ Docs](https://github.com/janyksteenbeek/laravel-gorse)[ GitHub Sponsors](https://github.com/janyksteenbeek)[ RSS](/packages/janyksteenbeek-laravel-gorse/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (17)Used By (0)

Laravel Gorse
=============

[](#laravel-gorse)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6ffab4197d74af5d58f95a03f0ef34829ef122d1128a348b25d8bf04df689b29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616e796b737465656e6265656b2f6c61726176656c2d676f7273652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/janyksteenbeek/laravel-gorse)[![Total Downloads](https://camo.githubusercontent.com/bdd20b62a6cb4c735e0d15bbba1662e56dffb640d99c8afbfe751d2195e9e75c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a616e796b737465656e6265656b2f6c61726176656c2d676f7273652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/janyksteenbeek/laravel-gorse)

A Laravel integration for the [Gorse](https://gorse.io) recommendation engine. This package provides a seamless way to integrate Gorse's recommendation capabilities into your Laravel application.

Features
--------

[](#features)

- Easy integration with Laravel's Eloquent models
- Automatic synchronization of users and items with Gorse
- Support for feedback tracking
- Simple recommendation retrieval
- Command-line tools for bulk synchronization

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 11.x or 12.x
- A running Gorse instance

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require janyksteenbeek/laravel-gorse
```

After installation, publish the configuration file:

```
php artisan vendor:publish --tag="gorse-config"
```

Configuration
-------------

[](#configuration)

Add the following environment variables to your `.env` file:

```
GORSE_API_KEY=your-api-key
GORSE_ENDPOINT=http://your-gorse-instance:8087

# Optional: Disable SSL verification for development/self-signed certificates
GORSE_VERIFY_SSL=false

# Optional: Enable automatic synchronization with Gorse
GORSE_AUTO_SYNC=false

# Optional: Enable automatic model resolving (default: true)
GORSE_RESOLVING_ENABLED=true
```

### SSL Verification

[](#ssl-verification)

By default, SSL certificate verification is enabled for security. However, in development environments or when using self-signed certificates, you may need to disable it. You can do this by setting `GORSE_VERIFY_SSL=false` in your `.env` file.

> **Note:** It's recommended to keep SSL verification enabled in production environments.

Usage
-----

[](#usage)

### Making Models Recommendable

[](#making-models-recommendable)

To make a model recommendable (e.g., products, articles), use the `HasGorseFeedback` trait:

```
use JanykSteenbeek\LaravelGorse\Traits\HasGorseFeedback;

class Product extends Model
{
    use HasGorseFeedback;

    // Optional: Customize Gorse integration
    protected function gorseCategories(): array
    {
        return ['products', $this->category];
    }

    protected function gorseLabels(): array
    {
        return [$this->type, $this->brand];
    }
}
```

### Making Users Receive Recommendations

[](#making-users-receive-recommendations)

To enable users to receive recommendations, use the `HasGorseRecommendations` trait:

```
use JanykSteenbeek\LaravelGorse\Traits\HasGorseRecommendations;

class User extends Model
{
    use HasGorseRecommendations;

    protected function gorseLabels(): array
    {
        return [self::class, $this->country];
    }
}
```

### Getting Recommendations

[](#getting-recommendations)

```
// Get recommendations for a user
$recommendations = $user->recommendations(10); // Get 10 recommendations

// Get category-specific recommendations
$recommendations = $user->categoryRecommendations('electronics', 10);

// Get popular items
$recommendations = $user->popularItems(10);

// Get popular items in a category
$recommendations = $user->popularItemsByCategory('electronics', 10);

// Get session-based recommendations
$recommendations = $user->sessionRecommendations([
    [
        'FeedbackType' => 'click',
        'ItemId' => 'product:123',
        'Timestamp' => '2024-03-20T12:00:00Z'
    ]
], 10);

// Get category-specific session recommendations
$recommendations = $user->sessionCategoryRecommendations('electronics', [
    [
        'FeedbackType' => 'click',
        'ItemId' => 'product:123'
    ]
], 10);

// Get similar users (neighbors)
$similarUsers = $user->userNeighbors(10);

// Record feedback
$user->feedback($product, 'like');
```

### Auto-Sync

[](#auto-sync)

The package supports automatic synchronization of your models with Gorse. When enabled, any changes to your models (create, update, delete) will be automatically synchronized with Gorse. You can enable this feature by setting `GORSE_AUTO_SYNC=true` in your `.env` file.

### Model Resolving

[](#model-resolving)

By default, when retrieving recommendations, the package will automatically resolve the recommended items into their respective Eloquent models. This means you'll get a collection of actual model instances instead of just IDs. You can disable this feature by setting `GORSE_RESOLVING_ENABLED=false` in your `.env` file.

### Manual Synchronization

[](#manual-synchronization)

The package provides commands to manually sync your data with Gorse:

```
# Sync all users
php artisan gorse:sync-users --model=App\\Models\\User --chunk=100

# Sync all items
php artisan gorse:sync-items --model=App\\Models\\Product --chunk=100
```

The `--chunk` option allows you to specify how many records should be processed at once (default: 100).

### Using the Facade

[](#using-the-facade)

You can also use the Gorse facade directly:

```
use JanykSteenbeek\LaravelGorse\Facades\Gorse;

// Get recommendations (resolved to model instances)
$recommendations = Gorse::getRecommendations($userId, 10);

// Get raw recommendations without model resolution
$rawRecommendations = Gorse::raw()->getRecommendations($userId, 10);
// Returns a Collection of: [['Id' => 'Product:1', 'Score' => 0.95], ...]

// All recommendation methods return Collections, making them Laravel-friendly
$rawRecommendations->pluck('Score')->avg(); // Get average score
$rawRecommendations->sortByDesc('Score'); // Sort by score
$rawRecommendations->filter(fn ($item) => $item['Score'] > 0.5); // Filter by score

// Or use resolveModels() to control resolution
$rawRecommendations = Gorse::resolveModels(false)->getRecommendations($userId, 10);

// Get category recommendations
$recommendations = Gorse::getCategoryRecommendations($userId, 'electronics', 10);

// Get popular items
$recommendations = Gorse::getPopularItems(10, $userId);

// Get popular items in category
$recommendations = Gorse::getPopularItemsByCategory('electronics', 10, $userId);

// Get session recommendations
$recommendations = Gorse::getSessionRecommendations($feedback, 10);

// Get session recommendations in category
$recommendations = Gorse::getSessionCategoryRecommendations('electronics', $feedback, 10);

// Get similar users
$recommendations = Gorse::getUserNeighbors($userId, 10);

// Insert feedback
Gorse::insertFeedback('like', $userId, $itemId);
```

All recommendation methods return Laravel Collections, regardless of whether model resolution is enabled. This means you can use all of Laravel's Collection methods on both resolved and raw results:

```
// Raw response with scores (as Collection)
$rawRecommendations = Gorse::raw()->getRecommendations($userId, 10);

// Use Collection methods on raw results
$highScoring = $rawRecommendations
    ->filter(fn ($item) => $item['Score'] > 0.8)
    ->sortByDesc('Score')
    ->values();

$averageScore = $rawRecommendations->pluck('Score')->avg();

// Resolved to models with scores (as Collection)
$recommendations = Gorse::getRecommendations($userId, 10);

// Use Collection methods on resolved models
$highScoring = $recommendations
    ->filter(fn ($model) => $model->gorse_score > 0.8)
    ->sortByDesc('gorse_score')
    ->values();

$averageScore = $recommendations->pluck('gorse_score')->avg();
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance45

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

16

Last Release

430d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff89bdcd628dcd42b4add24d5d88618df658f974c6909c54da30447bcc4faffc?d=identicon)[janyksteenbeek](/maintainers/janyksteenbeek)

---

Top Contributors

[![janyksteenbeek](https://avatars.githubusercontent.com/u/3578636?v=4)](https://github.com/janyksteenbeek "janyksteenbeek (18 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/janyksteenbeek-laravel-gorse/health.svg)

```
[![Health](https://phpackages.com/badges/janyksteenbeek-laravel-gorse/health.svg)](https://phpackages.com/packages/janyksteenbeek-laravel-gorse)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
