Laravel Unique Values

Laravel Unique Values stats

Downloads
0
Stars
4
Open Issues
0
Forks
0

View on GitHub →

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

Laravel Unique Values Banner

Package to generate unique values

Tests Coverage Analysis Total downloads

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

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

Installation

You can install the package via composer:

composer require justbetter/laravel-unique-values

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

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

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

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

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

Laravel Unique Values footer
justbetter photo

We're an innovative development agency from The Netherlands building awesome websites, webshops and web applications with Laravel and Magento.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Justbetter Laravel Unique Values Related Articles

Generate Persistent Unique Values in Laravel image

Generate Persistent Unique Values in Laravel

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec