Skip to content

Commit a267333

Browse files
committed
fix: Fixed #76
1 parent dc7b781 commit a267333

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Version.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ class Version extends Model
4040
'versionable',
4141
];
4242

43+
public function getIncrementing()
44+
{
45+
return \config('versionable.uuid') ? false : parent::getIncrementing();
46+
}
47+
48+
public function getKeyType()
49+
{
50+
return \config('versionable.uuid') ? 'string' : parent::getKeyType();
51+
}
52+
4353
protected static function booted()
4454
{
4555
static::creating(function (Version $version) {

tests/VersionWithUuidTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
class VersionWithUuidTest extends TestCase
6+
{
7+
protected function getEnvironmentSetUp($app)
8+
{
9+
parent::getEnvironmentSetUp($app);
10+
11+
$app['config']->set('versionable.uuid', true);
12+
}
13+
14+
public function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
Post::enableVersioning();
19+
20+
config([
21+
'auth.providers.users.model' => User::class,
22+
'versionable.user_model' => User::class,
23+
]);
24+
}
25+
26+
public function testUuid()
27+
{
28+
$user = User::create(['name' => 'overtrue']);
29+
$this->actingAs($user);
30+
31+
$post = Post::create(['title' => 'Hello world!', 'content' => 'Hello world!']);
32+
$version = $post->versions()->first();
33+
34+
$this->assertIsString($version->id);
35+
}
36+
}

0 commit comments

Comments
 (0)