michalkortas/laravel-uuid

Simply create Eloquent Models & database tables with UUID/GUID primary keys.

v1.0.4 2021-03-03 10:08 UTC

This package is auto-updated.

Last update: 2024-04-29 04:40:42 UTC


README

Simply create Eloquent Models & database tables with UUID/GUID primary keys.

Installation

composer require michalkortas/laravel-uuid

Usage

Add uuid as primary key in your table migration.

Schema::create('customers', function (Blueprint $table) {
    $table->uuid('id')->primary();
});

Add trait to your Eloquent Model.

<?php

namespace AppModels;

use michalkortas\LaravelUuid\traits\HasUuid;
use Illuminate\Database\Eloquent\Model;

class Customers extends Model
{
    use HasUuid;
}

Now, when you run migrations, newly created table has datatype ID as CHAR(36). UUID will be inserted automatically with Model::create() method.

ID datatype - UUID - CHAR(36)