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'

You can also specify the number of values to return:

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

A more advanced example, including configurable variables:

// Earmark(prefix, suffix, padding, min, max)
$earmark = new Earmark('ZULU', null, 10, 5000, null);

// Returns: 'ZULU0000005000'

// Returns: ['ZULU0000005001', 'ZULU0000005002', 'ZULU0000005003']

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


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

Laravel News Partners

Laravel Jobs

Software Developer
Remote (US & Canada)
😎 Laravel Developer
Jogg, Inc
Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
Saint Petersburg, FL and Remote
Senior PHP Developer (Laravel)
The Interaction Design Foundation
Fullstack Laravel Engineer (Munich/Remote) 💻
Munich, Germany or Remote