News

Generate a Unique Series of Values with Earmark

Published
Generate a Unique Series of Values with Earmark image

The Earmark Laravel package by Brian LaVallee generates values in a unique and customizable series:

A Laravel package to earmark sequential values in a series and eliminate any gaps in the series when values are unset. Allowing for reusable values.

It can be used to fetch the next value (or array of values) to be used in an application. Database locking prevents duplicate values from being returned.

Here’s some basic usage examples from the package’s readme:

First, you can get and unset (for reuse) values:

$serial = Earkmarked::get(); // Returns: '2010'
Earkmarked::unset($serial);

You can also specify the number of values to return:

// Returns: ['2011', '2012', '2013']
$serial = Earkmarked::get(3);
Earkmarked::unset($serial);

A more advanced example, including configurable variables:

// Earmark(prefix, suffix, padding, min, max)
$earmark = new Earmark('ZULU', null, 10, 5000, null);
 
// Returns: 'ZULU0000005000'
$earmark->get();
 
// Returns: ['ZULU0000005001', 'ZULU0000005002', 'ZULU0000005003']
$earmark->get(3);

The readme explains the nuts and bolts of how it works, so I’d recommend checking out the full readme and source code on GitHub at poing/earmark.

This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article