JoseCage/kallun-api

View on GitHub
app/Traits/UuidTrait.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Kallun\Traits;

use Ramsey\Uuid\Uuid;

/**
 * Auto generate a uuid to the given model.
 */
trait UuidTrait
{

    protected static function boot()
    {
        parent::boot();

        static::creating(function($model) {
            $model->{$model->getKeyNme()} = Uuid::uuid4()->toString();
        });
    }
}