Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117881290
UuidStrKeyTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
UuidStrKeyTrait.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline