A simple solution for providing UUID support for the IDs of your Eloquent models.
You can install the package via composer:
composer require glorand/laravel-eloquent-model-uuid
Let us start on the database side of things.
$table->uuid('id');
$table->primary('id');
//OR
$table->uuid('id')->primary();
Instead of extending the standard Laravel model class, extend from the model class provided by this package:
<?php
use Glorand\LaravelEloquentModelUuid\Database\Eloquent\Model;
class Entity extends Model
{
//
}
<?php
use Illuminate\Database\Eloquent\Model;
use Glorand\LaravelEloquentModelUuid\Database\Concerns\Uuid;
class Entity extends Model
{
use Uuid;
/**
* The "type" of the auto-incrementing ID.
*
* @var string
*/
protected $keyType = 'string';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
//
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email gombos.lorand@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.