hpolthof / laravel-eloquent-uuid
Add support for UUIDs to Eloquent
Requires
- dyrynda/laravel-efficient-uuid: ^2.3
- laravel/framework: ^5.8
- moontoast/math: ^1.1
- ramsey/uuid: ~3.8
Requires (Dev)
- orchestra/testbench: ^3.8
This package is auto-updated.
Last update: 2024-11-10 06:38:47 UTC
README
Allow the usage of UUID in a MySQL setup.
How to install?
Install the repository with composer
composer require hpolthof/laravel-eloquent-uuid
Laravel should auto-discover the required service providers.
How to use?
The package requires dyrynda/laravel-efficient-uuid,
this package will override the default behaviour of Laravel so that a uuid()
migration will not
become a VARCHAR(36)
but a BINARY(16)
field.
Trait
Next up you should use the trait Hpolthof\Laravel\EloquentUuid\Uuid
in your Eloquent model.
You'll have to add a method uuidColumns()
to your model. This should return an array with
the fields that are UUIDs.
protected function uuidColumns(): array { return ['id']; }
Primary Key
If you've added your primary key as a UUID column, the model will automatically set a new UUID on the creation of the model into the database.
Disclaimer
This package is used for internal development, but published for public use. Obviously this software comes as is, and there are no warranties or whatsoever.
If you like the package it is always appreciated if you drop a message of gratitude! ;-)
The package was build by: Paul Olthof