Eloquent memory give you a Laravel model based time machine to perform time traveling through your models state.
$article = Article::create([
'name' => 'Women, Life, Freedom',
'content' => 'Hey this content just added,',
]);
// 5 minutes later
// let's change the content
$article->update([
'content' => 'Hey this content just changed,'
]);
//
// Oops, we have changed our content by mistake, let's go back
$articleBeforeUpdate = $article->getStatyeOf(Carbon::now()->subMinutes(2));
$articleBeforeUpdate->save(); // will rollback the content of article to the 1 minute ago
You can install the package via composer:
composer require debuqer/eloquent-memory
You can publish and run the migrations with:
php artisan vendor:publish --tag="eloquent-memory-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="eloquent-memory-config"
This is the contents of the published config file:
return [
'changes' => [
'model-updated' => ModelUpdated::class,
'model-created' => ModelCreated::class,
'model-deleted' => ModelDeleted::class,
],
'drivers' => [
'default' => 'eloquent',
'eloquent' => [
'class_name' => \Debuqer\EloquentMemory\Repositories\Eloquent\EloquentTransitionPersistDriver::class,
'connection' => 'default',
],
],
];
In order to force models to keep track of their states, CanRememberStates trait must be used in the model class
use Debuqer\EloquentMemory\CanRememberStates;
class Post extends Model
{
use CanRememberStates;
}
The model records their states in a database and the states can be retrieved by method getStateOf
$oldArticle = Article::find(5)->getStateOf(Carbon::now()->subMinutes(5));
-
Fix migration, so the subject_key should be provide as an array
-
Fix migration to be publishable via laravel
-
no date_recorded field are stored
composer test
This package is in dev mode and not recommend to use in production environment
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.