PHPackages                             ignition-nbs/laravel-uuid-model - 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. ignition-nbs/laravel-uuid-model

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

ignition-nbs/laravel-uuid-model
===============================

Enable Laravel's Eloquent Model to be identified by UUID (string) rather than ID (increment or bigIncrement)

2.0.1(5y ago)12.7k↓100%MITPHP

Since Feb 7Pushed 5y agoCompare

[ Source](https://github.com/ignition-nbs/laravel-uuid-model)[ Packagist](https://packagist.org/packages/ignition-nbs/laravel-uuid-model)[ RSS](/packages/ignition-nbs-laravel-uuid-model/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Laravel UUID Model
==================

[](#laravel-uuid-model)

[![Latest Version on Github](https://camo.githubusercontent.com/53e3742987657ef8ca15bd485c3135ac868020cf48e2043b92b43318eab9c241/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f69676e6974696f6e2d6e62732f6c61726176656c2d757569642d6d6f64656c3f7374796c653d706c6173746963)](https://github.com/ignition-nbs/laravel-uuid-model)[![Latest version on Packagist](https://camo.githubusercontent.com/689b3767b722f369dc5e6fe388c685adac7330e43f9a49220178e363da3c538b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69676e6974696f6e2d6e62732f6c61726176656c2d757569642d6d6f64656c3f7374796c653d706c6173746963)](https://packagist.org/packages/ignition-nbs/laravel-uuid-model)[![Total Downloads](https://camo.githubusercontent.com/362dee4c9248859d728b6a93fa3f040557b00e9f9e15ee212ccab6cd98185a45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69676e6974696f6e2d6e62732f6c61726176656c2d757569642d6d6f64656c3f7374796c653d706c6173746963)](https://packagist.org/packages/ignition-nbs/laravel-uuid-model)

laravel-uuid-model provides 1 PHP Trait that implements the initialization function and is thus called by the `Illuminate\Database\Eloquent\Model`constructor. The `initializeUuidModel` sets `$incrementing` to FALSE, `$keyType`to`"string"`, and it will ensure that the `id` attribute can be mass-assigned.

Then it generates a version 4 universally unique identifier for the `id`attribute and sets that value already in `$this->attributes['id']`.

It is important to note that this Trait works better then UUID Model classes that extend Laravel's `Model` class: Classes that have intermediate parent classes (e.g. `App\User`) will not work with those type of UUID Model classes.

This package works with Laravel 5.7, 5.8, 6.x and 7.x.

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

[](#installation)

```
$ composer require ignition-nbs/laravel-uuid-model
```

If you do install and use this package, please send a postcard to

```
Ignition NBS Ltd
5th Floor
82 King Street
Manchester
M2 4WQ
United Kingdom

```

Usage
-----

[](#usage)

There are two things that you must do in order to make successful use of this `UuidModel`:

- Use `IgnitionNbs\LaravelUuidModel\UuidModel` inside your model class:

```
