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
$finder = $model;
if (\App\Utils::isSoftDeletable($model)) {
$finder = $finder->withTrashed();
}
while ($finder->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
Fri, Apr 24, 10:49 AM (1 w, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18785478
Default Alt Text
UuidStrKeyTrait.php (1 KB)

Event Timeline