Laravel package to generate unique identifiers

0.0.1 2018-08-23 07:37 UTC

This package is auto-updated.

Last update: 2024-11-05 01:30:57 UTC


README

Laravel package to create automatic unique nullable identifiers like u5CVsCnxyXg for your Eloquent models.

Installation

Require this package

composer require continuum-digital/uid

Usage

Configuration

Create a new entry in database.config.php to configure your uid's:

    'uid' => [
        'salt' => '', // Default ''
        'minLength' => '', // Default 0
        'alphabet' => '', // Default 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    ],

You can remove the salt, minLength or alphabet to use default values.

Database

Add the $table->uid() in your Schemas:

Schema::create('your_table', function (Blueprint $table) {
    $table->uid();
})

Eloquent

Add the HasUid trait to your Models to add the capabilities:

  • Local scope $model->uid($uid)
  • Automatic generation of uid during the creating event

Notes

This package use HashIds under the hood.