Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

mtvbrianking/laravel-eloquent-uuid

Repository files navigation

THIS PACKAGE IS NOT MAINTAINED ANYMORE...

LARAVEL HAS INTRODUCTED UUID & ULID SUPPORT IN THE CORE STARTING WITH LARAVEL V9

https://laravel.com/docs/9.x/eloquent#uuid-and-ulid-keys


Laravel Eloquent UUID.

Build Status Scrutinizer Code Quality Code Coverage StyleCI Documentation

Installation

Install via Composer package manager:

composer require bmatovu/laravel-eloquent-uuid

Usage

Migration:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateClientsTable extends Migration
{
    public function up()
    {
        Schema::create('clients', function (Blueprint $table) {
            $table->uuid('id');
            $table->string('name');
            // ...
            $table->timestamps();

            $table->primary('id');
        });
    }
}

Model:

use Bmatovu\Uuid\Traits\HasUuidKey;
use Illuminate\Database\Eloquent\Model;

class Client extends Model
{
    use HasUuidKey;
    
    /**
     * The "type" of the primary key ID.
     *
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;
}

Testing

Factories fail after faking events: (Issue #19952)

After calling Event::fake(), no event listeners will be executed. So, if your tests use model factories that use the HasUuidKey trait; you should call Event::fake() after using your factories.