Skip to content

Instantly share code, notes, and snippets.

@hongaar
Created September 30, 2014 12:09
Show Gist options
  • Save hongaar/b29e73caed41bb06423d to your computer and use it in GitHub Desktop.
Save hongaar/b29e73caed41bb06423d to your computer and use it in GitHub Desktop.

Revisions

  1. hongaar created this gist Sep 30, 2014.
    19 changes: 19 additions & 0 deletions UuidTrait.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?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();
    });
    }
    }