1. Go to this page and download the library: Download sthira-labs/version-vault 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/ */
sthira-labs / version-vault example snippets
use SthiraLabs\VersionVault\Traits\HasVersioning;
class Project extends Model
{
use HasVersioning;
public function tasks() { return $this->hasMany(Task::class); }
public function versioningConfig(): array
{
return [
'name',
'tasks:title' => [
'users:name,pivot(role)'
],
];
}
}
$project->recordVersion('created');
$project->recordVersionIfChanged('updated');
$result = $project->reconstructVersion(2);
$historic = $result->model;
$rollback = $project->rollbackToVersion(2);
public function versioningConfig(): array
{
return [
'amount',
// Reference mode: only FK tracked (no related attributes)
'owner' => true,
'manager' => true,
];
}
public function versioningConfig(): array
{
return [
'name',
// Snapshot mode (implicit because fields are listed)
'category:name',
'profile:bio',
'tasks:title',
'tags:name,pivot(order)',
// Or explicitly:
'owner' => [
'mode' => 'snapshot',
'attributes' => ['name', 'email'],
],
];
}