2017 © Pedro Peláez
 

library pkuuids

Using a UUID as PrimaryKey for laravel 5.3+

image

racklin/pkuuids

Using a UUID as PrimaryKey for laravel 5.3+

  • Tuesday, April 18, 2017
  • by racklin
  • Repository
  • 1 Watchers
  • 1 Stars
  • 424 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 15 % Grown

The README.md

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., (*1)

inspired by http://stackoverflow.com/questions/31817067/laravel-5-using-a-uuid-as-primary-key, (*2)

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();, (*3)

Models

Disable auto-increment primary key

Add $incrementing = false; to your Models., (*4)

Use Traits

Add use PkUuuids; to your Models., (*5)

Example:, (*6)

<?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+., (*7)

The Versions

18/04 2017

dev-master

9999999-dev

Using a UUID as PrimaryKey for laravel 5.3+

  Sources   Download

MIT

The Requires

 

by Rack Lin

laravel postgres