Created
September 30, 2014 12:09
-
-
Save hongaar/b29e73caed41bb06423d to your computer and use it in GitHub Desktop.
Laravel UuidTrait for Eloquent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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