PHPackages                             hans-thomas/lilac - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hans-thomas/lilac

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hans-thomas/lilac
=================

it is a recommender system based-on pairwise association rules.

v1.0.0(2y ago)120MITPHPPHP ^8.1

Since Jun 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hans-thomas/lilac)[ Packagist](https://packagist.org/packages/hans-thomas/lilac)[ RSS](/packages/hans-thomas-lilac/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

lilac
=====

[](#lilac)

It's a recommender system using pairwise association rules (PAR) based-on this [paper](https://www.sciencedirect.com/science/article/pii/S095741741830441X?via%3Dihub). There is an enhanced PAR (EPAR) algorithm which reduces the producing recommendation time. this recommender system is able to create train model and generate recommends for one or more than one model.

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

[](#installation)

Via composer

```
composer require hans-thomas/lilac
```

Then

```
php artisan vendor:publish --tag lilac-config
```

Usage
-----

[](#usage)

Let's assume there are two `Post` and `Category` models which they have a `many-to-many` relationship.

### Config

[](#config)

In config file, we should define our relationship first. there is a template definition of a relation that you can edit that.

```
// config/lilac.php

return [
    // ...

    'relations'                => [
        Post::class => [
            'wrappedByModel'                 => Category::class,
            'wrappedByModelRelationToEntity' => 'posts',
            'entityModelRelationToWrappedBy' => 'categories',
        ]
    ]
];
```

### Available methods

[](#available-methods)

#### recommends

[](#recommends)

To generate some recommendation, use `recommends` method.

```
use Hans\Lilac\Facades\Lilac;

Lilac::recommends( $ids );
```

It will return a collection of models that sorted by the score they've got.

#### updateTrainModel

[](#updatetrainmodel)

`Lilac` provides a caching system to store the created data and prevents to create duplicate train model. when you create some recommendation for a model(s), the related train model will be cached for future use. meanwhile, you make some changes in the relationship between you models. in this scenario, if you try to create some recommendation for you model, you will receive out-dated recommends. to fix this, you can run `updateTrainModel` for updated related model(s).

```
use Hans\Lilac\Facades\Lilac;

Lilac::updateTrainModel( $ids );
```

This will update and cache the related train model.

#### fresh

[](#fresh)

Sometimes you need to ignore cached train models and make recommendation using the latest data from database. for this, you can use `fresh` method before `recommends` method.

```
use Hans\Lilac\Facades\Lilac;

Lilac::fresh()->recommends( $ids );
```

#### cache

[](#cache)

You may want to create recommendation for two models in one scope. first one using fresh data and second one using cached data. in this situation, you should use `cache` in you second call.

```
use Hans\Lilac\Facades\Lilac;

Lilac::fresh()->recommends( $ids );

Lilac::cache()->recommends( $other_ids );
```

#### trainer

[](#trainer)

To set your trainer, you can pass the instance to the `trainer` method.

```
use Hans\Lilac\Facades\Lilac;
use Hans\Lilac\Trainers\EPAR;
use Hans\Lilac\Trainers\PAR;

Lilac::trainer( new EPAR( $ids ) )->recommends( $ids );
// or
Lilac::trainer( new PAR )->recommends( $ids );
```

> You can set your default trainer in config file.

#### limit

[](#limit)

You can set a limit to returned recommendation count.

```
use Hans\Lilac\Facades\Lilac;

Lilac::limit( 10 )->recommends( $ids );
```

### Jobs

[](#jobs)

To automatically keep train models up-to-date, there are two jobs than you can use. You can fire these jobs whenever you update the relationship or just setting hooks for you relationships using this [package](https://github.com/chelout/laravel-relationship-events).

#### UpdateEntityTrainModel

[](#updateentitytrainmodel)

To update the train model of a single model, you can fire `UpdateEntityTrainModel` and pass the related model.

#### UpdateWrapperTrainModel

[](#updatewrappertrainmodel)

To update the train model of a bunch of related models, you should pass them as a collection to `UpdateWrapperTrainModel` job.

Support
-------

[](#support)

- [Repost bugs](https://github.com/hans-thomas/lilac/issues)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.4% 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

Unknown

Total

1

Last Release

1073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bca622c2e351a8b18ffc2acc6365e99d9c5f16765a9cdc2a0f03110834bc1102?d=identicon)[hans-thomas](/maintainers/hans-thomas)

---

Top Contributors

[![hans-thomas](https://avatars.githubusercontent.com/u/39920372?v=4)](https://github.com/hans-thomas "hans-thomas (62 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")

---

Tags

pairwiserecommender-systemrules

### Embed Badge

![Health badge](/badges/hans-thomas-lilac/health.svg)

```
[![Health](https://phpackages.com/badges/hans-thomas-lilac/health.svg)](https://phpackages.com/packages/hans-thomas-lilac)
```

###  Alternatives

[alchemy/zippy

Zippy, the archive manager companion

47522.6M51](/packages/alchemy-zippy)[kotchuprik/php-short-id

Yet another Short ID generator. The library help you generate short id like youtube, vimeo, bit.ly, etc.

3054.4k](/packages/kotchuprik-php-short-id)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

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