28 lines
503 B
PHP
28 lines
503 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
trait InteractsWithUuid
|
|
{
|
|
public static function bootInteractsWithUuid()
|
|
{
|
|
static::creating(function ($model) {
|
|
if (empty($model->{$model->getKeyName()})) {
|
|
$model->{$model->getKeyName()} = Str::orderedUuid()->toString();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function getIncrementing()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function getKeyType()
|
|
{
|
|
return 'string';
|
|
}
|
|
}
|