From 833ec09ebc90a4c83c5d88d7ce3d65602d64c914 Mon Sep 17 00:00:00 2001 From: Froxz Date: Mon, 20 Feb 2023 13:01:43 +0200 Subject: [PATCH 1/3] Added a method to avoid creating revison --- src/Concerns/HasDrafts.php | 7 +++++++ tests/RevisionsTest.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Concerns/HasDrafts.php b/src/Concerns/HasDrafts.php index a541821..f0662e8 100644 --- a/src/Concerns/HasDrafts.php +++ b/src/Concerns/HasDrafts.php @@ -114,6 +114,13 @@ protected function newRevision(): void }); } + public function withoutRevision(): static + { + $this->shouldCreateRevision = false; + + return $this; + } + public function shouldCreateRevision(): bool { return $this->shouldCreateRevision; diff --git a/tests/RevisionsTest.php b/tests/RevisionsTest.php index 276385f..14e2b41 100644 --- a/tests/RevisionsTest.php +++ b/tests/RevisionsTest.php @@ -102,3 +102,19 @@ $this->assertDatabaseCount(SoftDeletingPost::class, 6); expect(SoftDeletingPost::withDrafts()->count())->toBe(6); }); + +it('save without revision', function () { + $post = Post::factory()->published()->create(['title' => 'Foo']); + $this->assertDatabaseCount('posts', 1); + + $post->withoutRevision(); + + $post->title = 'Bar'; + $post->save(); + + $this->assertDatabaseCount('posts', 1); + + $this->assertDatabaseHas('posts', [ + 'title' => $post->title + ]); +}); \ No newline at end of file From 64b4db5adffcbee7e6cf990e7eccf6c4a50e2c4a Mon Sep 17 00:00:00 2001 From: Froxz Date: Mon, 20 Feb 2023 13:26:07 +0200 Subject: [PATCH 2/3] Added to Readme.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index bfb1025..5859241 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,12 @@ $revisions = $post->revisions(); Deleting a record will also delete all of its revisions. Soft deleting records will soft delete the revisions and restoring records will restore the revisions. +If you need to update a record without creating revision + +```php +$post->withoutRevision()->update($options); +``` + ## Testing ```bash From 7716d47c339448795624b04740d49f5ca520898e Mon Sep 17 00:00:00 2001 From: oddvalue Date: Mon, 20 Feb 2023 16:09:14 +0000 Subject: [PATCH 3/3] Update RevisionsTest.php --- tests/RevisionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RevisionsTest.php b/tests/RevisionsTest.php index 14e2b41..e333855 100644 --- a/tests/RevisionsTest.php +++ b/tests/RevisionsTest.php @@ -117,4 +117,4 @@ $this->assertDatabaseHas('posts', [ 'title' => $post->title ]); -}); \ No newline at end of file +});