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

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

minusmillionaer/eloquent-uuid
=============================

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

v1.1(7y ago)098MITPHP

Since Dec 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/minusmillionaer/eloquent-uuid)[ Packagist](https://packagist.org/packages/minusmillionaer/eloquent-uuid)[ RSS](/packages/minusmillionaer-eloquent-uuid/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (11)Used By (0)

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

[](#eloquent-uuid)

An Eloquent UUID Trait to use with Laravel 5.8

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/feff22d5838b41d3f56a035b5585e5c78f29f95e3835236694f21f6b5403f8f2/68747470733a2f2f706f7365722e707567782e6f72672f6d696e75736d696c6c696f6e6165722f656c6f7175656e742d757569642f642f746f74616c2e737667)](https://packagist.org/packages/minusmillionaer/eloquent-uuid)[![StyleCI](https://camo.githubusercontent.com/aaf8e03c647489555333cd41381e5f68b2b7a04172afe4b3dcda58650bdc841c/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3138363536383033372f736869656c64)](https://github.styleci.io/repos/186568037/)

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 minusmillionaer/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:

```
