bmatovu/laravel-eloquent-uuid

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel Eloquent UUID.

v1.1.0 2021-03-20 19:08 UTC

This package is auto-updated.

Last update: 2023-03-01 06:54:04 UTC


README

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.