PHP code example of avocet-shores / laravel-rewind
1. Go to this page and download the library: Download avocet-shores/laravel-rewind library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
avocet-shores / laravel-rewind example snippets
use AvocetShores\LaravelRewind\Facades\Rewind;
// Previous title: 'Old Title'
$post->title = 'Updated Title';
$post->save();
// Title goes back to 'Old Title'
Rewind::rewind($post);
// Title goes forward to 'Updated Title'
Rewind::fastForward($post);
// Title goes back to 'Old Title'
Rewind::rewind($post);
$post->title = 'Rewind is Awesome!';
$post->save();
[
'version' => 3,
'old_values' => [
'title' => 'New Title', // Note: This is the title from v2, not v1
// Other attributes...
],
'new_values' => [
'title' => 'Rewind is Awesome!',
// Other attributes...
],
]
use AvocetShores\LaravelRewind\Traits\Rewindable;
class Post extends Model
{
use Rewindable;
}
$post = Post::find(1);
$post->title = "New Title";
$post->save();
// A new version is automatically created
use AvocetShores\LaravelRewind\Facades\Rewind;
// Rewind two versions back
Rewind::rewind($post, 2);
// Fast-forward one version
Rewind::fastForward($post);
// Jump directly to a specific version
Rewind::goTo($post, 5);
public static function excludedFromVersioning(): array
{
return ['password', 'api_token'];
}