Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
]);
});