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://percona.community/blog/2018/10/12/generating-identifiers-auto_increment-sequence/
The package currently only supports MySQL.
Installation
Please install the package via Composer:
Basic example
This example keeps things simple: Foo and Bar both use UUID primary keys,
and Bar.foo_id references Foo.id.
Migrations
Models
Usage
Examples
More scenarios are documented in the examples/ directory:
examples/01-single-model-uuid-primary-key.mdexamples/02-two-models-uuid-pk-and-fk.mdexamples/03-creating-entities-with-binary-uuid.mdexamples/04-creating-entities-with-string-uuid.mdexamples/05-querying.md
Configuration
If you want a global default UUID column name, publish the config and set the environment variable.
-
Publish the config file:
-
Set the default column name in
.env: - Refresh config:
Per-model override still works and takes precedence:
Troubleshooting
When the package reads a column that does not hold a binary UUID, it says so
directly instead of letting ramsey/uuid fail on the raw value:
UUIDs are stored as 16 raw bytes, so the column the package reads has to be the
binary one — set it per model with protected $uuidColumn = 'uuid'; or globally
with BINARY_UUID_DEFAULT_COLUMN. Assigning a value that is neither a UUID in
string form nor 16 raw bytes throws InvalidBinaryUuidException while the model
is being created, instead of writing it to the database.
Unit tests
Run this command if you want to check unit tests:
Or if you want to check code coverage: