8000 GitHub - racklin/pkuuids: Using a UUID as PrimaryKey for Laravel 5.3+
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

racklin/pkuuids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using a UUID as PrimaryKey for Laravel 5.3+

PkUuids package use ramsey/uuid[https://github.com/ramsey/uuid] (official installed on 5.3+) to generate a UUID_v4(random) as primary key for Eloquent Model.

inspired by http://stackoverflow.com/questions/31817067/laravel-5-using-a-uuid-as-primary-key

Install

  1. Use composer to add the package into your project using composer require racklin/pkuuids:dev-master

Migrations

Use a UUID as primary key, we need to change $table->increments('id'); to $table->uuid('id')->primary();

Models

Disable auto-increment primary key

Add $incrementing = false; to your Models.

Use Traits

Add use PkUuuids; to your Models.

Example:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Racklin\PkUuids\PkUuids;

class User extends Model
{
    use PkUuids;

    $incrementing = false;
}

Laravel version

Current package version works for Laravel 5.3+.

About

Using a UUID as PrimaryKey for Laravel 5.3+

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0