Skip to main content
Back to packages
208 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