PHPackages                             justbetter/laravel-unique-values - 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. [Caching](/categories/caching)
4. /
5. justbetter/laravel-unique-values

ActivePackage[Caching](/categories/caching)

justbetter/laravel-unique-values
================================

Package to generate unique values with support for concurrency utilizing cache locking

1.1.0(3mo ago)536.0k↓17.6%PHPPHP ^8.3CI passing

Since Mar 14Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/justbetter/laravel-unique-values)[ Packagist](https://packagist.org/packages/justbetter/laravel-unique-values)[ RSS](/packages/justbetter-laravel-unique-values/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (14)Versions (3)Used By (0)

[ ![Laravel Unique Values Banner](./art/banner.svg)](https://github.com/justbetter/laravel-unique-values "JustBetter")Package to generate unique values
=================================

[](#package-to-generate-unique-values)

 [![Tests](https://camo.githubusercontent.com/dc221f1c2cd0664c55092a5a10005d72fc4d92f9a04349582646a39e852de31b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d756e697175652d76616c7565732f74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-unique-values) [![Coverage](https://camo.githubusercontent.com/fae235ea770e24a71fd52eca366bed4d1c28415de7b63084e4fd42c6c74d9a69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d756e697175652d76616c7565732f636f7665726167652e796d6c3f6c6162656c3d636f766572616765267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-unique-values) [![Analysis](https://camo.githubusercontent.com/0f8c645eb71fe61cb40aa46e30865945dd99765eee4f9fca8cc9ba10c40d8124/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d756e697175652d76616c7565732f616e616c7973652e796d6c3f6c6162656c3d616e616c79736973267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-unique-values) [![Total downloads](https://camo.githubusercontent.com/2542605c675a7b61e791234e5281a1d978c7ff38a861cd05dbf995309773b968/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a7573746265747465722f6c61726176656c2d756e697175652d76616c7565733f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-unique-values)

This package generates persistent unique values with support for concurrency utilizing scoped cache locking. It stores generated unique values in the database.

Generated values are unique per scope and can be generated using a callback method. This package only supports strings.

Features
--------

[](#features)

- Generate unique values
- Support for concurrency
- Customizable generator
- Maximum attempts
- Support for subjects

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

[](#installation)

You can install the package via composer:

```
composer require justbetter/laravel-unique-values
```

Usage
-----

[](#usage)

```
use JustBetter\UniqueValues\Support\UniqueValue;

$uniqueValue = UniqueValue::make()
    ->scope('unique-scope')
    ->generator(function (int $attempt): string {
        return match ($attempt) {
            0 => 'unique-value',
            default => 'unique-value-'.$attempt,
        };
    })->generate();
```

Output after first run: `unique-value`. Output after second run: `unique-value-1`. Output after third run: `unique-value-2`.

### Maximum attempts

[](#maximum-attempts)

You can configure the maximum attempts, this is three by default. If the maximum attempts are reached an exception is thrown.

```
use JustBetter\UniqueValues\Support\UniqueValue;

$uniqueValue = UniqueValue::make()
    ->scope('unique-scope')
    ->attempts(2)
    ->generator(function (int $attempt): string {
        return match ($attempt) {
            0 => 'unique-value',
            default => 'unique-value-'.$attempt,
        };
    })->generate();
```

### Subject

[](#subject)

You can add a subject to retrieve a previously generated value for the subject. Optionally you can add an override flag to run the generation again for the subject.

```
use JustBetter\UniqueValues\Support\UniqueValue;

$uniqueValue = UniqueValue::make()
    ->scope('unique-scope')
    ->subject('subject')
    ->generator(function (int $attempt): string {
        return match ($attempt) {
            0 => 'unique-value',
            default => 'unique-value-'.$attempt,
        };
    })->generate();
```

First run will output: `unique-value`. Second run will output: `unique-value`. Only one unique value will be stored in the database.

Quality
-------

[](#quality)

To ensure the quality of this package, run the following command:

```
composer quality
```

This will execute three tasks:

1. Makes sure all tests are passed
2. Checks for any issues using static code analysis
3. Checks if the code is correctly formatted

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Vincent Boon](https://github.com/VincentBean)
- [Ramon Rietdijk](https://github.com/ramonrietdijk)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

[ ![Laravel Unique Values footer](./art/footer.svg)](https://justbetter.nl "JustBetter")

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~383 days

Total

2

Last Release

93d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d00b3f55cd4ae8b8cfb001a644ed6c7a1127a956c24375bcfe16ce12bd89bed?d=identicon)[justbetter](/maintainers/justbetter)

---

Top Contributors

[![VincentBean](https://avatars.githubusercontent.com/u/3906942?v=4)](https://github.com/VincentBean "VincentBean (5 commits)")[![ramonrietdijk](https://avatars.githubusercontent.com/u/85165272?v=4)](https://github.com/ramonrietdijk "ramonrietdijk (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/justbetter-laravel-unique-values/health.svg)

```
[![Health](https://phpackages.com/badges/justbetter-laravel-unique-values/health.svg)](https://phpackages.com/packages/justbetter-laravel-unique-values)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3417.0k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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