Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit a2996b7

Browse files
authored
Merge pull request #43 from vpratfr/master
Adds method to generate a UUID
2 parents 1b1b2a1 + 2e3c024 commit a2996b7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/HasBinaryUuid.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected static function bootHasBinaryUuid()
1515
return;
1616
}
1717

18-
$model->{$model->getKeyName()} = static::encodeUuid(Uuid::uuid1());
18+
$model->{$model->getKeyName()} = static::encodeUuid(static::generateUuid());
1919
});
2020
}
2121

@@ -49,6 +49,11 @@ public static function scopeWithUuidRelation(Builder $builder, $uuid, string $fi
4949
}, $uuid));
5050
}
5151

52+
public static function generateUuid() : string
53+
{
54+
return Uuid::uuid1();
55+
}
56+
5257
public static function encodeUuid($uuid): string
5358
{
5459
if (! Uuid::isValid($uuid)) {

tests/Feature/HasBinaryUuidTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ public function it_prevents_decoding_the_uuid_when_the_model_does_not_exist()
197197
$this->assertNull($model->uuid_text);
198198
}
199199

200+
/** @test */
201+
public function it_generates_uuids_in_binary_form()
202+
{
203+
$binaryUuid = TestModel::generateUuid();
204+
205+
$this->assertTrue(Uuid::isValid(TestModel::decodeUuid($binaryUuid)));
206+
}
207+
200208
/** @test */
201209
public function it_prevents_decoding_model_key_when_it_is_not_included_in_attributes()
202210
{

0 commit comments

Comments
 (0)