eig / eloquent-uuid
Easy UUID for Eloquent Models
Installs: 1 190
Dependents: 0
Suggesters: 0
Security: 0
Stars: 59
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.0.2
- eig/uuid: ^2.5.1
Requires (Dev)
- laravel/framework: >=9.3.0
- mockery/mockery: dev-master
- php-coveralls/php-coveralls: ^2.5.3
- phpunit/phpunit: ^9.5.10
README
A Package for easily adding UUID's to Eloquent Models supporting Laravel 5.5+
Usage
To use UUID in an Eloquent Model install the package with:
composer require eig/eloquent-uuid
Then in your Model instead of extending Model
extend EloquentUUID
like so:
<?php
namespace App;
use eig\EloquentUUID\EloquentUUID;
class UUIDModel extends EloquentUUID
{
}
Then in your migrations make sure you set id to string or uuid like this:
public function up()
{
Schema::create('client_models', function (Blueprint $table) {
$table->uuid('id');
$table->softDeletes();
$table->timestamps();
});
}
User UUID Model
For Laravel 5.3+, the standard user model that comes with the framework extends Authenticatble
for the new
multi-auth system. To add in UUID's to the user model extend eig\EloquentUUID\UUIDUser
which will add in the UUID
to the user while still extending Laravel's Authenticatable
class. The migration schema changes for extending
EloquentUUID
are the same for extending from UUIDUser
.
UUID Trait
As of version 1.1.0, EloquentUUID now has a trait named UUID
in the namespace eig\EloquentUUID\Traits\UUID
,
that you can use to compose a UUID class. The trait implements a UUID assignment in a __constructor()
method.
The migration schema changes for extending EloquentUUID
are the same for using the UUID
trait.
Supported PHP Versions
- 5.6+ Use the 1.x branch releases
- 7.0 Use the master branch releases of 2.x+
- 7.1 & Laravel 5.5 Use the master branch releases of 2.1
- 7.2 & Laravel 6-7 Use the master branch releases of 2.2
- 8.1 & Laravel 8.x+ Use the master branch releases of 3.0