Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 8002e1c

Browse files
authored
Merge pull request #29 from kslimani/fix-uuid-scope-trait
Make UUID fillable at entity creation using UUID scope trait
2 parents 37dda7c + ca6549b commit 8002e1c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/Support/UuidScopeTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ protected static function boot()
2727
parent::boot();
2828

2929
static::creating(function ($model) {
30-
$model->uuid = Uuid::generate()->string;
30+
if (empty($model->uuid)) {
31+
$model->uuid = Uuid::generate()->string;
32+
}
3133
});
3234
}
3335
}

tests/Unit/Entities/RoleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,14 @@ function test_it_syncs_permissions_by_array_of_uuids()
5151
});
5252
}
5353

54+
function test_it_can_fill_uuid_at_creation()
55+
{
56+
$uuid = '84e28c10-8991-11e7-ad89-056674746d73';
57+
58+
$roleNotFilled = factory(Role::class)->create();
59+
$this->assertNotEquals($uuid, $roleNotFilled->uuid);
60+
61+
$roleFilled = factory(Role::class)->create(['uuid' => $uuid]);
62+
$this->assertEquals($uuid, $roleFilled->uuid);
63+
}
5464
}

0 commit comments

Comments
 (0)