1. Go to this page and download the library: Download actcmsvn/data-synchronize 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/ */
actcmsvn / data-synchronize example snippets
namespace ACTCMS\Blog\Exporters;
use ACTCMS\Blog\Models\Post;
use ACTCMS\DataSynchronize\Exporter\ExportColumn;
use ACTCMS\DataSynchronize\Exporter\Exporter;
use Illuminate\Support\Collection;
class PostExporter extends Exporter
{
public function label(): string
{
return 'Posts';
}
public function columns(): array
{
return [
ExportColumn::make('name'),
ExportColumn::make('description'),
ExportColumn::make('created_at'),
];
}
public function collection(): Collection
{
return Post::all();
}
}
namespace ACTCMS\Blog\Http\Controllers;
use ACTCMS\DataSynchronize\Exporter\Exporter;
use ACTCMS\DataSynchronize\Http\Controllers\ExportController;
use ACTCMS\Blog\Exporters\PostExporter;
class ExportPostController extends ExportController
{
protected function getExporter(): Exporter
{
return PostExporter::make();
}
}
use ACTCMS\Base\Facades\AdminHelper;
use Illuminate\Support\Facades\Route;
use ACTCMS\Blog\Http\Controllers\ExportPostController;
AdminHelper::registerRoutes(function () {
Route::prefix('tools/data-synchronize')->name('tools.data-synchronize.')->group(function () {
Route::group(['prefix' => 'export/posts', 'as' => 'export.posts.', 'permission' => 'posts.export'], function () {
Route::get('/', [ExportPostController::class, 'index'])->name('index');
Route::post('/', [ExportPostController::class, 'store'])->name('store');
});
});
});
use ACTCMS\Base\Facades\PanelSectionManager;
use ACTCMS\Base\PanelSections\PanelSectionItem;
use ACTCMS\DataSynchronize\PanelSections\ExportPanelSection;
public function boot(): void
{
// ...
PanelSectionManager::setGroupId('data-synchronize')->beforeRendering(function () {
PanelSectionManager::default()
->registerItem(
ExportPanelSection::class,
fn () => PanelSectionItem::make('posts')
->setTitle('Posts')
->withDescription('Export post data to CSV or Excel file.')
->withPriority(120)
->withRoute('tools.data-synchronize.export.posts.index')
->withPermission('posts.export')
);
});
// ...
}
namespace ACTCMS\Blog\Importers;
use ACTCMS\Blog\Models\Post;
use ACTCMS\DataSynchronize\Importer\ImportColumn;
use ACTCMS\DataSynchronize\Importer\Importer;
class PostImporter extends Importer
{
public function chunkSize(): int
{
return 1000;
}
public function label(): string
{
return 'Posts';
}
public function getValidateUrl(): string
{
return route('tools.data-synchronize.import.posts.validate');
}
public function getImportUrl(): string
{
return route('tools.data-synchronize.import.posts.store');
}
public function getDownloadExampleUrl(): ?string
{
return route('tools.data-synchronize.import.posts.download-example');
}
public function columns(): array
{
return [
ImportColumn::make('name')->rules(['
namespace ACTCMS\Blog\Http\Controllers;
use ACTCMS\DataSynchronize\Http\Controllers\ImportController;
use ACTCMS\DataSynchronize\Importer\Importer;
class ImportPostController extends ImportController
{
protected function getImporter(): Importer
{
return PostImporter::make();
}
}
use ACTCMS\Base\Facades\PanelSectionManager;
use ACTCMS\Base\PanelSections\PanelSectionItem;
use ACTCMS\DataSynchronize\PanelSections\ImportPanelSection;
public function boot(): void
{
// ...
PanelSectionManager::setGroupId('data-synchronize')->beforeRendering(function () {
PanelSectionManager::default()
->registerItem(
ImportPanelSection::class,
fn () => PanelSectionItem::make('posts')
->setTitle('Posts')
->withDescription('Import post data from CSV or Excel file.')
->withPriority(120)
->withRoute('tools.data-synchronize.import.posts.index')
->withPermission('posts.import')
);
});
// ...
}