/ConciseUuid

A ConciseUuid Model for Eloquent / Laravel.

Primary LanguagePHPMIT LicenseMIT

ConciseUuid

ConciseUuid is an Eloquent Model that uses a concise UUIDv4 as the primary key.

A normal UUID is 36 characters and looks like:

d318fb95-5b49-47ca-abd5-326a60524e70

This is very long, and in base16, there is a lot of unnecessary space.

ConciseUuid takes this, strips out the "-" and converts the base16 into base62 (0-9, a-z, A-Z). Here is the Concise version of the above UUID:

Old: d318fb95-5b49-47ca-abd5-326a60524e70
New: 6QKnU3XheQMk3E6Vq1B4l6

As you can see, it is much more concise: 15 characters less!

Because of how the UUIDv4 algorithm is specified, a UUID will never begin with anything other than a number (0-9). So if you want a special class of UUIDs, pass in true. These UUIDs will always begin with a letter, letting you quickly differentiate them from normal UUIDs.

echo ConciseUuid::generateNewId(true);
// Output: rEBzkc6s67JU3kI7ZuA7TU

Usage

SQL: 
CREATE TABLE my_model (id char(22) primary key);

PHP:
namespace PHPExperts\ConciseUuid\ConciseUuidModel;

class MyModel extends ConciseUuidModel
{
}

For your users table:
namespace PHPExperts\ConciseUuid\ConciseUuidAuthModel;

class User extends ConciseUuidAuthModel
{
}

Installation

Via Composer

$ composer require phpexperts/conciseuuid

Having the GMP extension enabled really improves the execution time of this package.

Use cases

✔ Generate new id function will always return 22 characters long string ✔ Normal ids start with a number ✔ System generated ids start with a letter ✔ Can convert to a concise uuid ✔ Can convert to a uuid ✔ Can convert to a uuid without dashes ✔ Can generate new version 4 uuids ✔ Can strip slashes from uuids

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ phpunit

Contributing

Please take a look at contributing.md if you want to make improvements.

Credits

License

MIT license. Please see the license file for more information.