Skip to main content
Back to packages
206 GitHub stars

avocet-shores/laravel-rewind

View on GitHub

Description

Laravel Rewind is a powerful and efficient versioning package for your Eloquent models.

Navigating History

use AvocetShores\LaravelRewind\Facades\Rewind;
 
// Step backward/forward
Rewind::rewind($post, 2); // Go back 2 versions
Rewind::fastForward($post); // Go forward 1 version
 
// Jump to a specific version
Rewind::goTo($post, 5);
 
// Get the model's state at a specific point in time
$attributes = Rewind::versionAt($post, Carbon::parse('2025-01-15 14:30:00'));

Restoring State

There are two ways to go back to a previous version, and the distinction matters:

goTo() moves the pointer. The model is updated to match the target version, but no new version record is created. Good for previewing or navigating.

restore() creates a new version with the target version's state. The history shows the restore happened. Good for audit trails and compliance.

// Move the pointer (no audit trail of the move itself)
Rewind::goTo($post, 3);
 
// Create a new version from v3's state (audit trail preserved)
Rewind::restore($post, 3);
// $post is now at v8 (or whatever the next version is), with v3's attributes
// The version record has event_type 'restored' and meta['restored_from_version'] = 3

Recent Courses on Laravel Daily

[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks

7 lessons
43 min read

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

Queues in Laravel 13

18 lessons
1 h 12 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.