Looking to hire Laravel developers? Try LaraJobs

laravel-uuid maintained by michalkortas

Description
Simply create Eloquent Models & database tables with UUID/GUID primary keys.
Author
Last update
2021/03/03 11:08 (dev-master)
License
Downloads
499
Tags

Comments
comments powered by Disqus

laravel-uuid

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)