Last active
February 8, 2018 18:43
-
-
Save corean/c83887fdb9c348790f12f1dce4cae074 to your computer and use it in GitHub Desktop.
UUID #laravel #trait
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
| 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