1. Go to this page and download the library: Download hub-io/laravel-hubio-sync 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/ */
hub-io / laravel-hubio-sync example snippets
return [
'api_url' => rtrim((string) env('HUBIO_SYNC_URL', ''), '/'),
// Start a background sync after local changes and periodically while a screen polls.
'background' => (bool) env('HUBIO_SYNC_BACKGROUND', true),
'sync_interval_seconds' => (int) env('HUBIO_SYNC_INTERVAL', 60),
'timeout_seconds' => 20,
// Synchronized models by record type, in dependency order (referenced rows first).
'models' => [],
// Invokable class returning a stable device identity, so a reinstalled app gets its backup back.
'identity' => null,
// Invokable class called with a Household the device left or lost, before it is forgotten.
'forgetting' => null,
'default_device_name' => 'Môj telefón',
// Downloaded photos of other devices: disk and directory of the stored relative path.
'files' => [
'disk' => 'local',
'directory' => 'sync-files',
],
];
use Hubio\Sync\Concerns\Syncable;
use Hubio\Sync\Models\Household;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use Syncable;
protected $fillable = ['name', 'color'];
/** Payload uploaded to the server (reference other rows by UUID or natural key). */
public function syncData(): array
{
return ['name' => $this->name, 'color' => $this->color];
}
/** Local columns built from a downloaded payload (null skips the record for now). */
public static function syncAttributes(array $data, Household $household): ?array
{
return ['name' => (string) ($data['name'] ?? ''), 'color' => $data['color'] ?? '#6B7280'];
}
}