A simple Trait to provide UUID support for your Eloquent models
A simple, automatic UUID generator for any model based on Laravel 7 and above, By using this package when each new entry you will get the following :
- Generate
uuid
automatically . - Assign it to
uuid
field in database automatically. - easy find it based
uuid
method.
You can install the package via Composer:
composer require kadevland/simple-laravel-eloquent-uuid
There are two ways to use this package:
- with
uuid
in string formatKadevland\Eloquent\Uuid\Traits\HasUuid
- with
uuid
in bytes formatKadevland\Eloquent\Uuid\Traits\HasByteUuid
Import trait and set key type string or uuid if use string format.
By default UUID versions is v4
You can also specify v1 UUIDs to be used by setting in config file.
Use the HasUuid trait:
use Illuminate\Database\Eloquent\Model;
use Kadevland\Eloquent\Uuid\Traits\HasUuid;
class ExampleModel extends Model
{
use HasUuid;
protected $keyType = 'uuid';
/* or
protected $keyType = 'string';
*/
}
Use the HasByteUuid trait:
use Illuminate\Database\Eloquent\Model;
use Kadevland\Eloquent\Uuid\Traits\HasByteUuid;
class ExampleModel extends Model
{
use HasByteUuid;
protected $keyType = 'string';
}
##Config
You can publish the config file with:
php artisan vendor:publish --provider="kadevland/simple-laravel-eloquent-uuid" --tag="config"
composer test
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.