Page MenuHomePhorge

UuidIntKeyTrait.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

UuidIntKeyTrait.php

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

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:37 PM (2 h, 25 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
69/f3/7b73e2eedfa58b4a88e7edbbbb07
Default Alt Text
UuidIntKeyTrait.php (1 KB)

Event Timeline