PHP code example of anjan-talukdar / laravel-page-versioning
1. Go to this page and download the library: Download anjan-talukdar/laravel-page-versioning 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/ */
anjan-talukdar / laravel-page-versioning example snippets
use AnjanTalukdar\PageVersioning\Filament\PageVersioningPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
PageVersioningPlugin::make()
->navigationGroup('Content Management')
->navigationIcon('heroicon-o-document-duplicate')
->navigationSort(10),
]);
}
PageVersioningPlugin::make()
->resource(App\Filament\Resources\CustomPageResource::class)
'filament' => [
'resources' => [
'page' => App\Filament\Resources\CustomPageResource::class,
],
],
use AnjanTalukdar\PageVersioning\Services\PageService;
use AnjanTalukdar\PageVersioning\Enums\PageVersionStatus;
$service = app(PageService::class);
// 1. Create a logical page with initial version (version_code auto-set to 1)
$page = $service->createPage([
'type' => 'legal',
'slug' => 'privacy-policy',
], [
'title' => 'Privacy Policy',
'version_name' => 'v1.0.0', // Viewer version label
'content' => '<p>Privacy policy content...</p>',
], $userId = null, $publishImmediately = true);
// 2. Draft a new revision (version_code auto-incremented to 2)
$draftVersion = $service->createVersion($page, [
'title' => 'Privacy Policy (2027 Update)',
'version_name' => 'v1.1.0',
'content' => '<p>Updated privacy policy content...</p>',
'change_summary' => 'Updated data protection compliance terms',
], PageVersionStatus::DRAFT);
// 3. Publish a revision
$service->publishVersion($page, $draftVersion);
// 4. Safe Rollback to a past version (version_code auto-incremented to 3)
$service->rollbackToVersion($page, $oldVersion, 'Rollback to Initial Release');
return [
'register_routes' => true,
'route_prefix' => 'pages',
'route_middleware' => ['web'],
'layout' => 'public.layouts.app',
'default_types' => [
'legal' => 'Legal & Policies',
'general' => 'General Information',
],
];
bash
php artisan page-versioning:install
bash
php artisan page-versioning:install-filament
bash
php artisan vendor:publish --tag=page-versioning-filament
bash
php artisan vendor:publish --tag=page-versioning-views