1. Go to this page and download the library: Download visualbuilder/versionable 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/ */
visualbuilder / versionable example snippets
use Visualbuilder\Versionable\Versionable;
class Post extends Model
{
use Versionable;
/**
* Versionable attributes
*
* @var array
*/
protected $versionable = ['title', 'content'];
// Or use a blacklist
//protected $dontVersionable = ['created_at', 'updated_at'];
<...>
}
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Visualbuilder\Versionable\Version;
class Admin extends Authenticatable
{
use SoftDeletes;
public function versions()
{
return $this->morphMany(Version::class, 'user');
}
}
$post->versions; // all versions
$post->latestVersion; // latest version
// or
$post->lastVersion;
$post->versions->first(); // first version
// or
$post->firstVersion;
$post->versionAt('2022-10-06 12:00:00'); // get version from a specific time
// or
$post->versionAt(\Carbon\Carbon::create(2022, 10, 6, 12));
$post->getVersion(3)->revert();
// or
$post->revertToVersion(3);
class PostVersion extends \Visualbuilder\Versionable\Version
{
//
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Visualbuilder\Versionable\Versionable;
class Post extends Model
{
use Versionable;
public string $versionModel = PostVersion::class;
}