Download the PHP package verbanent/eloquent-binary-uuid without Composer
On this page you can find all versions of the php package verbanent/eloquent-binary-uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-binary-uuid
Ordered binary UUID in Laravel / Eloquent
Based on articles about the optimization of UUID storage in databases, I decided to write a simple library that allows this in my projects. I based on the information available here:
https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
https://www.percona.com/community-blog/2018/10/12/generating-identifiers-auto_increment-sequence/
The package currently only supports MySQL.
Installation
Please install the package via Composer:
Migration
Your model will use an ordered binary UUID, if you prepare a migration:
Or if you want to use a custom column name for the primary key:
Using UUID in models
All what you have to do, is use a new trait in models with UUID as a primary key:
The above example works for the column id
. If you use custom name for UUID column, you need to define it:
Abstract model for model with UUID
For your convenience you can extend your model with AbstractModel:
The above example works for the column id
. If you use custom name for UUID column, you need to define it:
Foreign binary UUID
If you would like to use UUID as a foreign key, use another trait and set $uuidable property for this model:
Getting a string form of UUID
The library is kept as simple as possible, so if you want to get a string form of UUID, just use a method:
or use a property, if you need a binary value:
Finding by primary UUID
For primary keys finding rows is simple and always return a model:
Finding by foreign UUID
For foreign keys finding rows requires a column name and returns collection of model:
Getting a foreign UUID string
You can print string form of your foreign UUID keys:
Because trying to have access to the property directly will print binary form of UUID:
Unit tests
Run this command if you want to check unit tests:
Or if you want to check code coverage: