#34 Generate UUID on seeder/models

This commit is contained in:
Nabeel Shahzad
2017-06-24 13:20:24 -05:00
parent 2aa7cc66d5
commit ba57cef0a7
9 changed files with 103 additions and 14 deletions

21
app/Models/UuidTrait.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Webpatser\Uuid\Uuid;
trait Uuids
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$key = $model->getKeyName();
if (empty($model->{$key})) {
$model->{$key} = Uuid::generate()->string;
}
#$model->{$model->getKeyName()} = Uuid::generate()->string;
});
}
}