PHPackages                             adamlien/pkuuids - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. adamlien/pkuuids

ActiveLibrary[Database &amp; ORM](/categories/database)

adamlien/pkuuids
================

Using a UUID as PrimaryKey for laravel 5.3+

v1.6(3y ago)076MITPHPPHP &gt;=5.4.0

Since Jul 13Pushed 3y agoCompare

[ Source](https://github.com/AdamLien/pkuuids)[ Packagist](https://packagist.org/packages/adamlien/pkuuids)[ RSS](/packages/adamlien-pkuuids/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (10)Used By (0)

Using a UUID as PrimaryKey for Laravel 5.3+
===========================================

[](#using-a-uuid-as-primarykey-for-laravel-53)

PkUuids package use `ramsey/uuid`\[\] (official installed on 5.3+) to generate a UUID\_v4(random) as primary key for `Eloquent Model`.

inspired by

Install
-------

[](#install)

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

Migrations
----------

[](#migrations)

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

Models
------

[](#models)

### Disable auto-increment primary key

[](#disable-auto-increment-primary-key)

Add `$incrementing = false;` to your Models.

### Use Traits

[](#use-traits)

Add `use PkUuuids;` to your Models.

Example:

```
