Skip to content

Instantly share code, notes, and snippets.

@corean
Last active February 8, 2018 18:43
Show Gist options
  • Select an option

  • Save corean/c83887fdb9c348790f12f1dce4cae074 to your computer and use it in GitHub Desktop.

Select an option

Save corean/c83887fdb9c348790f12f1dce4cae074 to your computer and use it in GitHub Desktop.
UUID #laravel #trait
trait UuidTrait
{
/**
* Defines the UUID field for the model.
* @return string
*/
protected static function uuidField()
{
return 'uuid';
}
/**
* Defines the UUID field for the model.
* @return string
*/
protected static function uuidField()
{
return 'uuid';
}
/**
* Use if boot() is overridden in the model.
*/
protected static function uuid()
{
static::creating(function ($model) {
$model->{self::uuidField()} = Uuid::uuid4()->toString();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment