Page MenuHomePhorge

UuidStrKeyTrait.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

UuidStrKeyTrait.php

<?php
namespace App\Traits;
trait UuidStrKeyTrait
{
/**
* Boot function from Laravel.
*/
protected static function bootUuidStrKeyTrait()
{
static::creating(function ($model) {
if (empty($model->{$model->getKeyName()})) {
$allegedly_unique = \App\Utils::uuidStr();
// Verify if unique
if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($model))) {
while ($model->withTrashed()->find($allegedly_unique)) {
$allegedly_unique = \App\Utils::uuidStr();
}
} else {
while ($model->find($allegedly_unique)) {
$allegedly_unique = \App\Utils::uuidStr();
}
}
$model->{$model->getKeyName()} = $allegedly_unique;
}
});
}
/**
* Get if the key is incrementing.
*
* @return bool
*/
public function getIncrementing()
{
return false;
}
/**
* Get the key type.
*
* @return string
*/
public function getKeyType()
{
return 'string';
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Apr 4, 1:15 AM (1 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d4/dd/2c430b4e883e2fa0f41494800253
Default Alt Text
UuidStrKeyTrait.php (1 KB)

Event Timeline