kadevland/simple-laravel-eloquent-uuid

A simple Trait provides the ability to use UUID generator in your Eloquent models

v1.0.1 2020-07-14 14:44 UTC

This package is auto-updated.

Last update: 2025-01-19 03:43:54 UTC


README

A simple Trait to provide UUID support for your Eloquent models

A simple, automatic UUID generator for any model based on Laravel 7 and above, By using this package when each new entry you will get the following :

  • Generate uuid automatically .
  • Assign it to uuid field in database automatically.
  • easy find it based uuid method.

Installation

You can install the package via Composer:

 composer require kadevland/simple-laravel-eloquent-uuid

Usage

There are two ways to use this package:

  • with uuid in string format Kadevland\Eloquent\Uuid\Traits\HasUuid
  • with uuid in bytes format Kadevland\Eloquent\Uuid\Traits\HasByteUuid

Import trait and set key type string or uuid if use string format.

By default UUID versions is v4

You can also specify v1 UUIDs to be used by setting in config file.

Uuid string format

Models

Use the HasUuid trait:

use Illuminate\Database\Eloquent\Model;
use Kadevland\Eloquent\Uuid\Traits\HasUuid;

class ExampleModel extends Model
{
  use HasUuid;
  
  protected $keyType = 'uuid';
  /* or
  protected $keyType = 'string';
  */       
}

Uuid bytes format

Models

Use the HasByteUuid trait:

use Illuminate\Database\Eloquent\Model;
use Kadevland\Eloquent\Uuid\Traits\HasByteUuid;

class ExampleModel extends Model
{
  use HasByteUuid;

  protected $keyType = 'string';  

}

##Config

You can publish the config file with:

php artisan vendor:publish --provider="kadevland/simple-laravel-eloquent-uuid" --tag="config"

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.