Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-uuid maintained by kdaws-com

Description
Eloquent UUID Trait for Laravel
Author
Last update
2021/09/20 15:37 (dev-main)
License
Downloads
11

Comments
comments powered by Disqus

laravel-uuid

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A pair of Eloquent Model Traits for dealing with orderable UUID primary or secondary keys.

Usage

Primary Keys

Model

Use \KDAWScom\LaravelUuid\HasUuidPrimary;

class MyModel extends Model
{
    Use HasUuidPrimary;
}

Migration

return new class extends Migration
{
    public function up()
    {
        Schema::create('my_models', function (Blueprint $table) {
            $table->string('id', 36)->primary();
            
            // OR
            
            $table->string('myKeyNameWillBeAutoDiscovered', 36)->primary();
        }
    }
}

Secondary Keys

Model

Use \KDAWScom\LaravelUuid\HasUuidSecondarys;

class MyModel extends Model
{
    Use HasUuidSecondary;
}

Migration

return new class extends Migration
{
    public function up()
    {
        Schema::create('my_models', function (Blueprint $table) {
            /**
             * Default key name is uuid 
             */
            $table->string('uuid', 36);

            /**
             * You can also set your own key name, but you must remember to set the value of:
             *
             * $laravelUuidSecondaryKeyName
             * 
             * to the key name inside your models boot routine
             */

            $table->string('myUuidKey', 36);
        }
    }
}