Generate a Unique Series of Values with Earmark

Generate a Unique Series of Values with Earmark

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

Filed in: News

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer
Remote
FPV Exchange
Senior Full-Stack Developer
Remote, USA Only
Givebutter
Full Stack Web Developer
Greenville, TX (or Remote, US)
Innovation First International, Inc.
Senior Software Developer
UK/Germany Only
The Greenhouse People Ltd
Senior PHP Developer
Cary, NC
INE