1. Go to this page and download the library: Download plank/snapshots 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/ */
plank / snapshots example snippets
namespace App\Http\Middleware;
use Closure;
use Plank\Snapshots\Contracts\ManagesVersions;
class SetActiveVersion
{
public function __construct(
protected ManagesVersions $versions
) {
}
public function handle($request, Closure $next)
{
$version = $request->route('version');
if ($version = $this->versions->byNumber($version)) {
$this->versions->setActive($version);
}
return $next($request);
}
}
use Plank\Snapshots\Facades\SnapshotSchema;
use Plank\Snapshots\Migrations\SnapshotBlueprint;
use Plank\Snapshots\Migrations\SnapshotMigration;
return new class extends SnapshotMigration
{
public function up()
{
$this->schema->create('blocks', function (SnapshotBlueprint $table) {
$table->id();
$table->unsignedBigInteger('page_id');
$table->string('name');
$table->morphs('blockable');
$table->timestamps();
$table->foreign('page_id')->references('id')->onSnapshot('pages');
});
}
public function down()
{
SnapshotSchema::dropIfExists('blocks');
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Plank\Snapshots\Concerns\AsVersionedContent;
use Plank\Snapshots\Contracts\Versioned;
class Page extends Model implements Versioned
{
use AsVersionedContent;
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Plank\Snapshots\Concerns\InteractsWithVersionedContent;
class User extends Model
{
use InteractsWithVersionedContent;
public function pages()
{
return $this->belongsToMany(Page::class);
}
}