{"id":51045322,"url":"https://github.com/whilesmartphp/eloquent-syncables","last_synced_at":"2026-06-22T13:02:29.532Z","repository":{"id":364593910,"uuid":"1268364804","full_name":"whilesmartphp/eloquent-syncables","owner":"whilesmartphp","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-13T16:06:33.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"dev","last_synced_at":"2026-06-13T18:11:27.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whilesmartphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-13T12:51:41.000Z","updated_at":"2026-06-13T16:06:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/whilesmartphp/eloquent-syncables","commit_stats":null,"previous_names":["whilesmartphp/eloquent-syncables"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/whilesmartphp/eloquent-syncables","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-syncables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-syncables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-syncables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-syncables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whilesmartphp","download_url":"https://codeload.github.com/whilesmartphp/eloquent-syncables/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-syncables/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34649822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-22T13:02:28.655Z","updated_at":"2026-06-22T13:02:29.523Z","avatar_url":"https://github.com/whilesmartphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eloquent Syncables\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/whilesmart/eloquent-syncables.svg?style=flat-square)](https://packagist.org/packages/whilesmart/eloquent-syncables)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/whilesmart/eloquent-syncables/tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/whilesmart/eloquent-syncables/actions?query=workflow%3Atests+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/whilesmart/eloquent-syncables.svg?style=flat-square)](https://packagist.org/packages/whilesmart/eloquent-syncables)\n\n**Eloquent Syncables** is a lightweight Laravel package that allows you to easily track when Eloquent models are synchronized with client devices. It supports tracking last synchronization times and mapping client-generated UUIDs and device tokens to database records.\n\n---\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require whilesmart/eloquent-syncables\n```\n\nYou should publish and run the migrations:\n\n```bash\nphp artisan vendor:publish --tag=\"syncables-migrations\"\nphp artisan migrate\n```\n\nYou can optionally publish the config file:\n\n```bash\nphp artisan vendor:publish --tag=\"syncables-config\"\n```\n\nThis will create a `config/syncables.php` file in your application directory.\n\n---\n\n## Usage\n\n### Preparing Your Models\n\nAdd the `Syncable` trait to any Eloquent model you want to track:\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Whilesmart\\Syncables\\Traits\\Syncable;\n\nclass Post extends Model\n{\n    use Syncable;\n}\n```\n\n### Sync Lifecycle\n\n#### Automatic Sync Creation\nWhenever a model using the `Syncable` trait is created, an associated `ModelSyncState` is automatically created with the current timestamp:\n\n```php\n$post = Post::create(['title' =\u003e 'New Syncable Record']);\n// A sync state is automatically created.\n```\n\n#### Mapping Client Generated IDs and Devices\nYou can record client-generated UUIDs and associate them with a user device.\n\n**Method A: Delimited Value**\n```php\n$post-\u003esetClientGeneratedId('iphone_15_pro:763261a8-c2b6-4bfa-8739-9d52410a56f2', $user);\n```\n\n**Method B: Separate Client ID and Device Token**\n```php\n$post-\u003esetClientGeneratedId('763261a8-c2b6-4bfa-8739-9d52410a56f2', $user, 'iphone_15_pro');\n```\n\n\u003e [!NOTE]\n\u003e Device association requires the suggested package `whilesmart/laravel-user-devices`. If not present, the package will safely bypass device creation and store only the client-generated ID.\n\n#### Fetching Sync State Details\n```php\n// Retrieve the last sync date\n$lastSynced = $post-\u003elast_synced_at; // e.g., \"2026-06-13 16:00:00\"\n\n// Retrieve the colon-delimited client ID\n$clientId = $post-\u003eclient_generated_id; // e.g., \"iphone_15_pro:763261a8-c2b6-4bfa-8739-9d52410a56f2\"\n```\n\n#### Updating Synced Status\nTo update the `last_synced_at` timestamp on subsequent sync events:\n\n```php\n$post-\u003emarkAsSynced();\n```\n\n---\n\n## Testing\n\nYou can run the package test suite using:\n\n```bash\ncomposer test\n```\n\n---\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhilesmartphp%2Feloquent-syncables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhilesmartphp%2Feloquent-syncables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhilesmartphp%2Feloquent-syncables/lists"}