1. Go to this page and download the library: Download zuko/syncro-sheet 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/ */
use Zuko\SyncroSheet\Contracts\SheetSyncable;
class Product extends Model implements SheetSyncable
{
public function getSheetIdentifier(): string
{
return '1234567890-your-google-sheet-id';
}
public function getSheetName(): string
{
return 'Products';
}
public function toSheetRow(): array
{
return [
$this->id,
$this->name,
$this->price,
$this->stock,
$this->updated_at->format('Y-m-d H:i:s')
];
}
public function getBatchSize(): ?int
{
return 500; // Optional, defaults to config value
}
}
use Zuko\SyncroSheet\Services\SyncManager;
// Full sync
$syncManager = app(SyncManager::class);
$syncState = $syncManager->fullSync(Product::class);
// Partial sync
$syncState = $syncManager->partialSync(Product::class, [1, 2, 3]);
use SyncroSheet;
// or
use Zuko\SyncroSheet\Facades\SyncroSheet;
// Full sync
$syncState = SyncroSheet::fullSync(Product::class);
// Partial sync
$syncState = SyncroSheet::partialSync(Product::class, [1, 2, 3]);
// Get last sync state
$lastSync = SyncroSheet::getLastSync(Product::class);
use Zuko\SyncroSheet\Events\SyncEvent;
Event::listen(SyncEvent::SYNC_STARTED, function ($syncState) {
Log::info("Sync started for {$syncState->model_class}");
});
Event::listen(SyncEvent::SYNC_COMPLETED, function ($syncState) {
Log::info("Sync completed: {$syncState->total_processed} records");
});
use Zuko\SyncroSheet\Notifications\BaseNotification;
class CustomSyncNotification extends BaseNotification
{
protected function getMailMessage(): MailMessage
{
return (new MailMessage)
->subject('Custom Sync Notification')
->line('Your custom notification logic here');
}
protected function getSlackMessage(): SlackMessage
{
return (new SlackMessage)
->content('Custom Slack notification');
}
}
use Zuko\SyncroSheet\Services\StateManager;
$stateManager = app(StateManager::class);
// Get last successful sync
$lastSync = $stateManager->getLastSuccessfulSync(Product::class);
// Get sync history
$syncHistory = \Zuko\SyncroSheet\Models\SyncState::where('model_class', Product::class)
->with('entries')
->latest()
->get();
use Zuko\SyncroSheet\Services\ErrorHandler;
try {
$syncManager->fullSync(Product::class);
} catch (GoogleSheetsException $e) {
// Handle Google Sheets specific errors
} catch (SyncException $e) {
// Handle general sync errors
}
public function getBatchSize(): int
{
return $this->hasMedia() ? 100 : 1000;
}
use Zuko\SyncroSheet\Notifications\SyncFailedNotification;
class SlackSyncNotifier extends Notification
{
public function toSlack($notifiable)
{
// Custom Slack notification logic
}
}