Skip to content

Instantly share code, notes, and snippets.

@gclove
Forked from bolechen/HasUuid.php
Created May 8, 2019 04:06
Show Gist options
  • Save gclove/397012a31730341dd98f17f649b1439e to your computer and use it in GitHub Desktop.
Save gclove/397012a31730341dd98f17f649b1439e to your computer and use it in GitHub Desktop.
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait UsesUuid
{
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'uuid';
}
protected static function bootUsesUuid()
{
static::creating(function ($model) {
$model->uuid = Str::orderedUuid();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment