PHPackages                             antriver/laravel-registers - 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. [Database &amp; ORM](/categories/database)
4. /
5. antriver/laravel-registers

ActiveLibrary[Database &amp; ORM](/categories/database)

antriver/laravel-registers
==========================

A way to keep a simple list of models belonging to another model. e.g. Users that have liked a Post.

6.0.0(2y ago)0673MITPHPPHP &gt;=7.1

Since Oct 24Pushed 2y ago1 watchersCompare

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

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

Laravel Registers
=================

[](#laravel-registers)

This package provides 'registers', which are simple lists of models 'belonging to' another model. For example, a list of `User`s who have liked a `Post`. Or a list of `Achievement`s a `User` has earnt. The registers also take care of caching what items are on the list.

Terminology
-----------

[](#terminology)

The `owner` of a register is the model the list belongs to. In the case of a 'post likers' register, this would be the `Post` model.

The `object` is what you add to the register / check is on the register / delete from the register. In the case of a 'post likers' register, this would be the `User` model.

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

[](#installation)

```
composer require antriver/laravel-registers

```

Integration
-----------

[](#integration)

Create a class that extends either `AbstractBooleanRegister` or `AbstractValueRegister`.

### `AbstractBooleanRegister`

[](#abstractbooleanregister)

This type of register serves as a simple 'is it here or not' list. Example use: Users who have liked a Post.

### `AbstractValueRegister`

[](#abstractvalueregister)

This type of register allows the same setting/checking as `AbstractBooleanRegister` but you can also set some data. Examples use: Users who have voted on a Post. The additional data would be the user's vote.

The only difference between the two is `AbstractBooleanRegister`'s `check()` method will return a boolean. But `AbstractValueRegister` will return whatever data you stored about the entry.

In both cases you must implement these methods:

### `create($object, array $data = [])`

[](#createobject-array-data--)

This should add an entry to the database to permanently store the action that has been performed (e.g. INSERT an entry in the post\_likes or post\_votes table). This should return an integer to show the result.

- 1 = Object was added to the register.
- 2 = Object was already on the register and so was modified.
- 0 = Object was already on the register but the value was the same, so was not modified.

The easiest way to get these return values is to use a unique key on the 2 IDs on your database table (e.g. a unique key on postId + userId for a post likers register.) Then the query you run in `create()` should use some form of `ON DUPLICATE KEY UPDATE` and return the number of rows affected.

Hints:

The post will be accessible as `$this-owner`, the user will be the passed in `$object`.

### `destroy($object)`

[](#destroyobject)

This should delete the row in the database relating to the action (e.g. DELETE the entry from the post\_likes table) and return the number of rows affected. If this returns 0 an exception will be thrown, as that meant the object was not on the register.

### `load()`

[](#load)

This should return all of the items on the register (e.g. SELECT all the entries about this post from the post\_likes table). This method should return an associative array where the keys are the IDs of the objects and the value is information about that object's entry.

For `AbstractValueRegister` this is straightforward - return whatever value you stored about the entry (e.g. which way the user voted, in the case of a post voters register.)

For `AbstractBooleanRegister` this may make less sense, but you can return anything as the value. It's recommended to just use something like `true`. The reason the array is this way round is that it can be much faster to use isset() (cheking against the key) than in\_array() (checking against the value) on larger arrays (see http://maettig.com/1397246220).

You can use the `buildObjectsArrayFromLoadedData()` helper method to provide the return value.

Examples
--------

[](#examples)

See [`ExamplePostLikesRegister.php`](tests/Repositories/ExamplePostLikesRegister.php) and [`ExamplePostVotesRegister.php`](tests/Repositories/ExamplePostVotesRegister.php) for example implementations.

Usage
-----

[](#usage)

Both `AbstractBooleanRegister` and `AbstractValueRegister` provide the same public methods.

### `add($object, array $data = [])`

[](#addobject-array-data--)

Add the object to the register. Ignore the `$data` property if using the `AbstractBoolenRegister`.

### `remove($object)`

[](#removeobject)

Remove the object from the register.

### `check($object)`

[](#checkobject)

For `AbstractBooleanRegister`, returns `true` or `false` if the object is on the register.

For `AbstractValueRegister`, returns the stored data if the object is on the register, otherwise returns `null`.

### `all()`

[](#all)

Returns all the objects on the register.

### `keys()`

[](#keys)

Returns the primary keys of all the objects on the register.

### `count()`

[](#count)

Returns the number of objects on the register.

### `refresh()`

[](#refresh)

Updates the cache of objects on the register.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Recently: every ~590 days

Total

24

Last Release

739d ago

Major Versions

1.1.6 → 2.0.22017-02-27

2.2.7 → 3.0.02022-08-11

3.0.0 → 6.0.02024-05-03

PHP version history (3 changes)2.2.0PHP &gt;=7.0.0

3.0.0PHP &gt;=7.1.0

6.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7dc40f9d37443cd47fc0079800c1ea6cee515b4efce4e0dfb942f15969a82a39?d=identicon)[antriver](/maintainers/antriver)

---

Top Contributors

[![antriver](https://avatars.githubusercontent.com/u/251159?v=4)](https://github.com/antriver "antriver (36 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antriver-laravel-registers/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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