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
Install via Composer package manager:
composer require bmatovu/laravel-eloquent-uuid
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;
}
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.