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
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
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
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup