Page MenuHomePhorge

UuidStrKeyTrait.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

UuidStrKeyTrait.php

<?php
namespace App\Traits;
use App\Utils;
trait UuidStrKeyTrait
{
/**
* Boot function from Laravel.
*/
protected static function bootUuidStrKeyTrait()
{
static::creating(static function ($model) {
if (empty($model->{$model->getKeyName()})) {
$allegedly_unique = Utils::uuidStr();
// Verify if unique
$finder = $model;
if (Utils::isSoftDeletable($model)) {
$finder = $finder->withTrashed();
}
while ($finder->find($allegedly_unique)) {
$allegedly_unique = 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
Sun, Apr 5, 11:48 PM (1 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
29/3a/cfc34a09f2a13d9a86841d0574f4
Default Alt Text
UuidStrKeyTrait.php (1 KB)

Event Timeline