Skip to content

Instantly share code, notes, and snippets.

@codyphobe
Forked from hongaar/UuidTrait.php
Created June 13, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codyphobe/f82adf9b9b0d14d2aa254072032c5dd5 to your computer and use it in GitHub Desktop.
Save codyphobe/f82adf9b9b0d14d2aa254072032c5dd5 to your computer and use it in GitHub Desktop.
Laravel UuidTrait for Eloquent
<?php
use Rhumsaa\Uuid\Uuid;
trait UuidTrait
{
/**
* Boot the Uuid trait for the model.
*
* @return void
*/
public static function bootUuidTrait()
{
static::creating(function($model) {
$model->incrementing = false;
$model->{$model->getKeyName()} = Uuid::uuid4()->__toString();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment