Created
July 22, 2017 19:17
-
-
Save kicco/624ead0e97ec6374c20aced833647e00 to your computer and use it in GitHub Desktop.
Laravel 5.4 UuidTrait instead on incrementing id
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 | |
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