phpvms/app/Models/Traits/Uuids.php
2017-08-14 18:26:20 -05:00

22 lines
437 B
PHP

<?php
namespace App\Models\Traits;
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;
});
}
}