A CUID generator

v2.0.0 2021-03-19 07:45 UTC

This package is auto-updated.

Last update: 2024-03-19 14:07:44 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616c69636173746c652f637569643f7374796c653d666c61742d737175617265 Packagist Version

A CUID (Collision Resistant Unique Identifier) is a method of creating a unique identifier that was developed by Eric Elliott. The purpose is to create unique IDs for use in web applications to better support horizontal scaling and sequential lookup performance.

Install

composer require calicastle/cuid

Example Usages

use CaliCastle\Cuid;

Cuid::make(); // ckbe1q3gi000001jsfnm9cm81
Cuid::make('u'); // ukbe1qos1000201js74bwas75

Laravel Eloquent

use CaliCastle\Concerns\HasCuid;

// Each user will have an id of something 
// like "ukbe1q3gi000001jsfnm9cm81"
class User extends Model 
{
   use HasCuid;

   /**
    * Get the CUID prefix.
    */
   public static function getCuidPrefix(): string
   {
       return 'u';
   }
}