PHPackages                             snowbuilds/laravel-mirror - 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. snowbuilds/laravel-mirror

ActiveLibrary

snowbuilds/laravel-mirror
=========================

Laravel recommendation engine

0.0.3-alpha(2y ago)152732MITPHPPHP ^8.1

Since Aug 7Pushed 2y ago3 watchersCompare

[ Source](https://github.com/SnowLaboratory/Laravel-Mirror)[ Packagist](https://packagist.org/packages/snowbuilds/laravel-mirror)[ Docs](https://github.com/snowbuilds/laravel-mirror)[ RSS](/packages/snowbuilds-laravel-mirror/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (11)Versions (4)Used By (0)

[![Laravel Mirror Package Logo](/art/laravel-mirror-banner.png)](/art/laravel-mirror-banner.png)

 [ ![Latest Version on Packagist](https://camo.githubusercontent.com/2041320e5e2b2ffe87e0555ed78526e235c0c2a5df4aba17c8876a126c51948d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736e6f776275696c64732f6c61726176656c2d6d6972726f722e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/snowbuilds/laravel-mirror) [ ![Total Downloads](https://camo.githubusercontent.com/cb33c3dc691282385384427cd42b542b4e974c727de6ed2998f390f0be1012eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736e6f776275696c64732f6c61726176656c2d6d6972726f722e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/snowbuilds/laravel-mirror) [ ![GitHub Actions](https://github.com/SnowLaboratory/Laravel-Mirror/actions/workflows/main.yml/badge.svg) ](#)

- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
    - [Weighted Averages](#weighted-averages)
    - [Compare Different Properties](different-properties-in-the-same-calculation)
    - [Custom Scoring Algorithms](#custom-scoring-algorithms)
    - [Combining Weights &amp; Custom Algorithms](#combining-weights-with-custom-algorithms)
    - [Organizing Code](#managing-multiple-algorithms-and-weights)
    - [Macros](#macros-extracting-algorithms)
- [Relationships](#relationships)
- [Generate Recommendations](#generate)
- [Roadmap](#roadmap)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

Introduction
------------

[](#introduction)

Bring your user experience to the next level! Laravel Mirror lets you suggest content to your users intelligently! Easily recommend blog posts, products, recipes, books, etc., with pure PHP! Start by registering a recommendation strategy and routinely updating recommendations in a CRON job!

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

[](#installation)

You can install the package via composer:

```
composer require "snowbuilds/laravel-mirror:^0.0.3-alpha"
```

```
php artisan vendor:publish --provider="SnowBuilds\Mirror\MirrorServiceProvider"
```

Usage
-----

[](#usage)

Registering a strategy is as simple as comparing two values! We added some utilities for convenience. For example, recommending blog posts with similar titles:

```
use SnowBuilds\Mirror\Concerns\Recommendations;
use SnowBuilds\Mirror\Mirror;

class Post extends Model
{
    use Recommendations;

    public function registerRecommendations(): void
    {
        $this->registerStrategy(Post::class)
            ->levenshtein('title');
    }
}
```

### Weighted Averages

[](#weighted-averages)

It is possible to combine algorithms! For example, suggesting posts with similar titles and tags. Adding weights will give fields precedence. Larger numbers have higher precedence. We made the title field score higher in a recommendation engine than the tags:

```
public function registerRecommendations(): void
{
    $this->registerStrategy(Post::class)
        ->levenshtein('title', 2)
        ->euclidean('tags', 1);
}
```

### Different Properties in the Same Calculation

[](#different-properties-in-the-same-calculation)

You can add a second parameter to the utility method when comparing properties with different names. For example, users should see posts based on their biography and followed communities:

```
class User extends Model
{
    use Recommendations;

    public function registerRecommendations(): void
    {
        $this->registerStrategy(Post::class)
            ->levenshtein('biography', 'title', 1) // compare biography to post title
            ->euclidean('communities', 'tags', 3); // compare communities to post tags
    }
}
```

### Custom Scoring algorithms

[](#custom-scoring-algorithms)

When the helper utilities are insufficient, you can invoke custom algorithms using the `using` method. The first value, `$a`, is the model that has recommendations, and the second value, `$b`, is the model being suggested:

```
class User extends Model
{
    public function registerRecommendations(): void
    {
        $this->registerStrategy(Post::class)
            ->using(function (User $a, Post $b) {
                return Algorithm::levenshtein($a->name, $b->name);
            });
    }
}
```

### Combining Weights with Custom Algorithms

[](#combining-weights-with-custom-algorithms)

Weights can also be applied to custom algorithms. The weights are applied in the order that the algorithm was registered. Our custom title comparator will take precedence over our tag comparator:

```
public function registerRecommendations(): void
{
    $this->registerStrategy(Post::class)
        ->using(function ($a, $b) {
            return Algorithm::levenshtein($a->title, $b->title);
        })
        ->using(function ($a, $b) {
            return Algorithm::euclidean($a->tags, $b->tags);
        })
        ->weights([2,1]);
}
```

### Managing Multiple Algorithms and Weights

[](#managing-multiple-algorithms-and-weights)

The code becomes hard to read when using multiple custom algorithms and weights. If you use an associative array, you can keep your algorithms and weights organized:

```
public function registerRecommendations(): void
{
    $this->registerStrategy(Post::class)
        ->using([
            'titles' => fn ($a, $b) => Algorithm::levenshtein($a->title, $b->title),
            'tags' => fn ($a, $b) => Algorithm::levenshtein($a->tags, $b->tags),
        ])
        ->weights([
            'titles' => 2,
            'tags' => 1,
        ]);
}
```

### Macros - Extracting Algorithms

[](#macros---extracting-algorithms)

When your custom algorithm is too cumbersome, you can extract it into a macro. We use an internal utility for registering algorithms, which you are free to use in your macros. This will create a clean utility API `->huggingFace` for our user model:

```
// ServiceProvider.php
ScoringStrategy::macro('huggingFace', function (...$args) {
  return $this->registerAlgorithm(
    fn($a, $b) => HuggingFace::invokeEmbedding($a, $b),
    ...$args
  );
});

// Model.php
class User extends Model
{
    public function registerRecommendations(): void
    {
        $this->registerStrategy(User::class)
            ->euclidean('follewers')
            ->huggingFace('activity')
            ->levenshtein('bio');
    }
}
```

Relationships
-------------

[](#relationships)

You can define a relationship between the model and the suggested content using the `morphsRecommendation` method. The content is ordered by the most suggested content:

```
class User extends Authenticatable
{
    use Recommendations;

    public function recommendedRecipes() {
        return $this->morphRecommendation(Recipe::class);
    }
}
```

Generating Recommendation Matrix
--------------------------------

[](#generating-recommendation-matrix)

Calculating recommendations is resource-intensive. Laravel Mirror provides a command for syncing recommendations. After syncing, the recommendations are stored in the database and you will be able to fetch related suggestions:

```
php artisan mirror:sync
```

In production, this should be a CRON job or registered in the Laravel kernel.

```
class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('mirror:sync')->daily();
    }
}
```

Roadmap
-------

[](#roadmap)

- Blazingly Fast!
- Polymorphic recommendations
- Recommendation collections
- Common comparison algorithms
- Sync command
- Testing
- Programmatically invoke syncing actions
- Simplified API for weights and faceted algorithms
- Queueing
- More algorithms
- More settings

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Code of Conduct
---------------

[](#code-of-conduct)

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

Credits
-------

[](#credits)

- [Snow Labs](https://github.com/snowbuilds)
- [Inspiration for Laravel Mirror](https://oliverlundquist.com/2019/03/11/recommender-system-with-ml-in-laravel.html)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity40

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 ~2 days

Total

3

Last Release

1005d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f1231368b2f25d0e17fbd038d7d95bdd1206e442ac8ef4bc3c941e94b991ecf?d=identicon)[Snow Builds](/maintainers/Snow%20Builds)

---

Top Contributors

[![ZebTheWizard](https://avatars.githubusercontent.com/u/13527122?v=4)](https://github.com/ZebTheWizard "ZebTheWizard (20 commits)")

---

Tags

content-suggestembeddingslaravel-packagerecommendation-enginerecommendation-systemsnowbuildslaravel-mirror

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/snowbuilds-laravel-mirror/health.svg)

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

###  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)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laravel/folio

Page based routing for Laravel.

608453.9k27](/packages/laravel-folio)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

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

The official AI SDK for Laravel.

732506.3k60](/packages/laravel-ai)

PHPackages © 2026

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