forked from rodrigopedra/laravel-cloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.php
43 lines (37 loc) · 782 Bytes
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
use Ramsey\Uuid\UuidFactory;
use Ramsey\Uuid\Codec\OrderedTimeCodec;
/**
* Get a hashid.
*
* @param int $value
* @return string
*/
function hashid_encode($value)
{
$hashids = new Hashids\Hashids(config('app.key'), 36);
return $hashids->encode($value);
}
/**
* Decode a hashid.
*
* @param string $value
* @return int
*/
function hashid_decode($value)
{
$hashids = new Hashids\Hashids(config('app.key'), 36);
return $hashids->decode($value)[0];
}
/**
* Get a new UUID.
*
* @var string
*/
function uuid()
{
$orderedTimeFactory = new UuidFactory;
$orderedTimeFactory->setCodec(new OrderedTimeCodec($orderedTimeFactory->getUuidBuilder()));
$orderedTimeUuid = $orderedTimeFactory->uuid1();
return (string) $orderedTimeUuid;
}