Download the PHP package minusmillionaer/eloquent-uuid without Composer
On this page you can find all versions of the php package minusmillionaer/eloquent-uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download minusmillionaer/eloquent-uuid
More information about minusmillionaer/eloquent-uuid
Files in minusmillionaer/eloquent-uuid
Package eloquent-uuid
Short Description A Laravel Eloquent Model trait for using UUID's as primary keys
License MIT
Informations about the package eloquent-uuid
eloquent-uuid
An Eloquent UUID Trait to use with Laravel 5.8
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
Use
In order to make it faster, you have the option to use one of three traits:
UuidModelTrait
- the key must beCHAR(36)
and contains the dashesUuid32ModelTrait
- the key must beCHAR(32)
, the dashes are strippedUuidBinaryModelTrait
- the key isBINARY(16)
.
Using UuidModelTrait
In order to use this trait, your schema must be something like:
Using Uuid32ModelTrait
For this type, just use CHAR(32)
in your schema (this is identical to the first one, but with stripped dashes).
Using UuidBinaryModelTrait
This stores the key as binary. The default Laravel Blueprint
curretly
does not currently support binary fields with specified length,
and (at least in MySQL) you cannot create an index (including primary key) on a BINARY
field without length.
So, the schema definition should be something like this (please double check if you're not using MySQL):
There are two additional notes for this particular trait.
Note 1. In order to get a string representation of your uuid, simple call
$model->id_string
and you'll get it.Note 2. You can use
User::find($uuid)
with both the binary version or the string (bin2hex) version.
Using the optimized uuid
To use the optimized uuid, put the following line in your models:
private static $uuidOptimization = true;
In your models
In order to use this in your models, just put use Uuid[32|Binary]ModelTrait;
:
Running tests
To run the tests, just run composer install
and ./vendor/bin/phpunit
.