Skip to content

Instantly share code, notes, and snippets.

@kicco
Created July 22, 2017 19:17
Show Gist options
  • Save kicco/624ead0e97ec6374c20aced833647e00 to your computer and use it in GitHub Desktop.
Save kicco/624ead0e97ec6374c20aced833647e00 to your computer and use it in GitHub Desktop.
Laravel 5.4 UuidTrait instead on incrementing id
<?php
namespace App;
use Ramsey\Uuid\Uuid;
trait HasPrimaryUUID
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->{$model->getKeyName()} = Uuid::uuid4()->toString();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment