Page MenuHomePhorge

UuidIntKeyTrait.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

UuidIntKeyTrait.php

<?php
namespace App\Traits;
trait UuidIntKeyTrait
{
/**
* Boot function from Laravel.
*/
protected static function bootUuidIntKeyTrait()
{
static::creating(function ($model) {
if (empty($model->{$model->getKeyName()})) {
$allegedly_unique = \App\Utils::uuidInt();
// Verify if unique
if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($model))) {
while ($model->withTrashed()->find($allegedly_unique)) {
$allegedly_unique = \App\Utils::uuidInt();
}
} else {
while ($model->find($allegedly_unique)) {
$allegedly_unique = \App\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
Sun, Apr 5, 11:47 PM (1 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
46/5f/621fbc17b4be78a4df17d0e8b320
Default Alt Text
UuidIntKeyTrait.php (1 KB)

Event Timeline