PHP code example of overtrue / laravel-versionable
1. Go to this page and download the library: Download overtrue/laravel-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/ */
overtrue / laravel-versionable example snippets
use Overtrue\LaravelVersionable\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'];
<...>
}
$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 \Overtrue\LaravelVersionable\Version
{
//
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelVersionable\Versionable;
class Post extends Model
{
use Versionable;
public string $versionModel = PostVersion::class;
}