Skip to content

Commit

Permalink
Merge pull request #15 from Froxz/no-revisions
Browse files Browse the repository at this point in the history
Added a method to avoid creating revison
  • Loading branch information
oddvalue authored Feb 20, 2023
2 parents fd16f48 + 7716d47 commit 362616e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Concerns/HasDrafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ protected function newRevision(): void
});
}

public function withoutRevision(): static
{
$this->shouldCreateRevision = false;

return $this;
}

public function shouldCreateRevision(): bool
{
return $this->shouldCreateRevision;
Expand Down
16 changes: 16 additions & 0 deletions tests/RevisionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
});

0 comments on commit 362616e

Please sign in to comment.