PHPackages                             alsofronie/eloquent-uuid - 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. alsofronie/eloquent-uuid

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

alsofronie/eloquent-uuid
========================

A Laravel Eloquent Model trait for using UUID's as primary keys

v1.0.9(8y ago)93332.8k↓17.3%28[2 PRs](https://github.com/alsofronie/eloquent-uuid/pulls)10MITPHPCI failing

Since Dec 14Pushed 5y ago5 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (10)Used By (10)

eloquent-uuid
=============

[](#eloquent-uuid)

An Eloquent UUID Trait to use with Laravel 5.1 - 5.4

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/3a24376373c2e3d9efa12136ebd344d6f3b09a2cfb041d8cde393bc5b130ab92/68747470733a2f2f706f7365722e707567782e6f72672f616c736f66726f6e69652f656c6f7175656e742d757569642f646f776e6c6f616473)](https://packagist.org/packages/alsofronie/eloquent-uuid)

It **should** work with Laravel 5.0 also, but it's untested.

The trait overwrites the static `boot` method and listens to the `creating`event. It generates a UUID (strips the dashes) and stores it in the primary key attribute. Thus, you'll need a `CHAR(32)` primary key for your model (see migrations below).

Installation
------------

[](#installation)

```
composer require alsofronie/eloquent-uuid:dev-master

```

Use
---

[](#use)

In order to make it faster, you have the option to use one of three traits:

- `UuidModelTrait` - the key must be `CHAR(36)` and contains the dashes
- `Uuid32ModelTrait` - the key must be `CHAR(32)`, the dashes are stripped
- `UuidBinaryModelTrait` - the key is `BINARY(16)`.

#### Using `UuidModelTrait`

[](#using-uuidmodeltrait)

In order to use this trait, your **schema** must be something like:

```
