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
Laravel News Partners

Laravel Jobs

Backend Software Engineer (PHP Developer)
Austin TX, Bonita Springs FL
Certified eSupport Corp
Backend PHP Developer
Hamburg, Germany
Full-Stack Engineer (Mid to Senior)
Remote (EST, CST)
Senior Laravel Developer (AI Applications)
Remote from anywhere in the UK or from our London office
GreenShoot Labs
Full Stack Engineer


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