Skip to content

Instantly share code, notes, and snippets.

@kicco
Created July 22, 2017 19:17

Revisions

  1. kicco created this gist Jul 22, 2017.
    19 changes: 19 additions & 0 deletions HasPrymaryUuidTrait.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?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();

    });
    }
    }