1. Go to this page and download the library: Download fedorlabs/sync-forge 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/ */
fedorlabs / sync-forge example snippets
$result = $syncForge->for(Product::class)
->key(['externalId'])
->source($rows)
->chunkSize(1000)
->deleteMissing(false)
->run();
echo $result->inserted; // new rows
echo $result->updated; // changed rows
echo $result->deleted; // deleted rows (zero when deleteMissing is disabled)
echo $result->unchanged; // skipped (no diff)
final class ProductSyncService
{
public function __construct(private readonly SyncForge $syncForge) {}
public function sync(iterable $rows): void
{
$this->syncForge->for(Product::class)
->key(['externalId'])
->source($rows)
->chunkSize(1000)
->deleteMissing(false)
->run();
}
}