Skip to content

Commit

Permalink
fix: Fixed #76
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jul 4, 2024
1 parent dc7b781 commit a267333
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class Version extends Model
'versionable',
];

public function getIncrementing()
{
return \config('versionable.uuid') ? false : parent::getIncrementing();
}

public function getKeyType()
{
return \config('versionable.uuid') ? 'string' : parent::getKeyType();
}

protected static function booted()
{
static::creating(function (Version $version) {
Expand Down
36 changes: 36 additions & 0 deletions tests/VersionWithUuidTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Tests;

class VersionWithUuidTest extends TestCase
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);

$app['config']->set('versionable.uuid', true);
}

public function setUp(): void
{
parent::setUp();

Post::enableVersioning();

config([
'auth.providers.users.model' => User::class,
'versionable.user_model' => User::class,
]);
}

public function testUuid()
{
$user = User::create(['name' => 'overtrue']);
$this->actingAs($user);

$post = Post::create(['title' => 'Hello world!', 'content' => 'Hello world!']);
$version = $post->versions()->first();

$this->assertIsString($version->id);
}
}

0 comments on commit a267333

Please sign in to comment.