PHPackages                             techparse/offline-sync - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. techparse/offline-sync

ActiveNativephp-plugin[Utility &amp; Helpers](/categories/utility)

techparse/offline-sync
======================

Offline-first synchronization plugin for NativePHP Mobile

v0.1.0(1mo ago)00MITPHPPHP ^8.1CI passing

Since Apr 21Pushed 1mo agoCompare

[ Source](https://github.com/Kromaric/offlinesync)[ Packagist](https://packagist.org/packages/techparse/offline-sync)[ RSS](/packages/techparse-offline-sync/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

NativePHP Offline Sync &amp; Backup
===================================

[](#nativephp-offline-sync--backup)

[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/acffb6ae1962992d26e4466782832787e79504a6250f80d732c4283458b9f497/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e737667)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/3175622456391a682cf88ceead140931b11da49b0f2f27b78371ad97f776a9b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531302e3025374325354531312e302d6f72616e67652e737667)](https://laravel.com)[![NativePHP Version](https://camo.githubusercontent.com/0c83bc1d6a4783b68df445cf574496189d7befc07f7889b0e71c13239c6b87e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6e61746976657068702d253545302e382e302d707572706c652e737667)](https://nativephp.com)[![Live Demo](https://camo.githubusercontent.com/ca43f194df59d2489aeb6080af4147a74241fdea88c7d41619881c62e38464be/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64656d6f2d6c6976652d3633363666312e737667)](https://offlinesync.techparse.fr)

**Offline-first synchronization plugin for NativePHP Mobile applications.**

Stop fighting with offline data. This plugin handles queuing, sync, and conflicts so you can focus on building features. Works out-of-the-box with zero native code required.

---

✨ Features
----------

[](#-features)

- ✅ **Automatic Queue Management** - Operations are automatically queued when offline
- ✅ **Bidirectional Sync** - Push local changes and pull remote updates
- ✅ **4 Conflict Resolution Strategies** - Server wins, Client wins, Last write wins, Merge
- ✅ **Auto-Connectivity Monitoring** - Syncs automatically when connection returns
- ✅ **Background Sync** - Works even when app is closed (iOS/Android)
- ✅ **Secure by Default** - HTTPS enforcement, auth-agnostic design (your app controls auth)
- ✅ **Observable** - Laravel events, logs, Artisan commands
- ✅ **Zero Native Code** - All native bridges included (Kotlin + Swift)

---

📋 Requirements
--------------

[](#-requirements)

- **PHP** ≥ 8.1
- **Laravel** ≥ 10.0
- **NativePHP** ≥ 0.8.0
- **iOS** ≥ 14.0
- **Android** API Level ≥ 24 (Android 7.0)

---

🚀 Installation
--------------

[](#-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require techparse/offline-sync
```

### 2. Register the Plugin

[](#2-register-the-plugin)

```
php artisan native:plugin:register techparse/offline-sync
```

### 3. Publish Configuration

[](#3-publish-configuration)

```
php artisan vendor:publish --tag=offline-sync-config
```

### 4. Run Migrations

[](#4-run-migrations)

```
php artisan migrate
```

### 5. Configure Your API

[](#5-configure-your-api)

Edit `.env`:

```
SYNC_API_URL=https://api.yourapp.com
SYNC_REQUIRE_HTTPS=true
```

---

📖 Quick Start
-------------

[](#-quick-start)

### 1. Add Syncable Trait to Your Models

[](#1-add-syncable-trait-to-your-models)

```
use Techparse\OfflineSync\Traits\Syncable;

class Task extends Model
{
    use Syncable;

    // Optional: customize sync behavior
    protected $syncResourceName = 'tasks';
    protected $syncExcluded = ['internal_notes'];
}
```

### 2. Map Resources in Config

[](#2-map-resources-in-config)

Edit `config/offline-sync.php`:

```
'resource_mapping' => [
    'tasks' => \App\Models\Task::class,
    'users' => \App\Models\User::class,
],
```

### 3. Use It!

[](#3-use-it)

```
// Operations are automatically queued when offline
$task = Task::create(['title' => 'My Task']);

// Manual sync (optional)
use Techparse\OfflineSync\Facades\OfflineSync;

OfflineSync::sync(['tasks']);

// Check status
$status = OfflineSync::getStatus();
// ['pending_count' => 5, 'is_syncing' => false, 'last_sync' => '...']
```

---

🎯 Usage
-------

[](#-usage)

### Automatic Syncing

[](#automatic-syncing)

With the `Syncable` trait, all create/update/delete operations are automatically queued:

```
// These are automatically queued when offline
$task = Task::create(['title' => 'New Task']);
$task->update(['completed' => true]);
$task->delete();
```

### Manual Syncing

[](#manual-syncing)

```
use Techparse\OfflineSync\Facades\OfflineSync;

// Bidirectional sync (push + pull)
OfflineSync::sync(['tasks', 'users']);

// Push only (local → server)
OfflineSync::push(['tasks']);

// Pull only (server → local)
OfflineSync::pull(['users']);
```

### Queue Management

[](#queue-management)

```
// Get pending items
$pending = OfflineSync::getPending();
$pendingTasks = OfflineSync::getPending('tasks');

// Purge old synced items (older than 7 days)
OfflineSync::purgeOldItems(7);
```

### Artisan Commands

[](#artisan-commands)

```
# Push local changes to server
php artisan sync:push

# Push specific resources
php artisan sync:push tasks users

# Pull remote changes
php artisan sync:pull tasks users

# Check queue status
php artisan sync:status

# Clear queue
php artisan sync:clear
php artisan sync:clear --failed
```

---

⚔️ Conflict Resolution
----------------------

[](#️-conflict-resolution)

Configure in `config/offline-sync.php`:

```
'conflict_resolution' => [
    // Default strategy for all resources
    'default_strategy' => 'server_wins',

    // Per-resource strategies
    'per_resource' => [
        'tasks' => 'last_write_wins',
        'users' => 'server_wins',
    ],
],
```

### Available Strategies

[](#available-strategies)

StrategyDescriptionBest For**server\_wins**Server data always overwrites localCritical data, auth**client\_wins**Local data always overwrites serverUser preferences**last\_write\_wins**Newest timestamp winsMost use cases**merge**Intelligent field-level mergeComplex data---

🔐 Security
----------

[](#-security)

### Authentication

[](#authentication)

The plugin is **auth-agnostic** — it does not manage tokens or credentials. Your application is responsible for authentication. To forward an auth header on every sync request, set `offline-sync.security.headers` at runtime (e.g. in your `AppServiceProvider`):

```
// app/Providers/AppServiceProvider.php
public function boot(): void
{
    $token = $this->app->make(Request::class)->bearerToken();

    if ($token) {
        config(['offline-sync.security.headers' => [
            'Authorization' => 'Bearer ' . $token,
        ]]);
    }
}
```

This works with any auth system: Laravel Sanctum, Passport, API keys, etc.

### HTTPS Enforcement

[](#https-enforcement)

```
SYNC_REQUIRE_HTTPS=true
```

---

📡 Backend Setup
---------------

[](#-backend-setup)

### Routes

[](#routes)

Add to `routes/api.php`:

```
use Techparse\OfflineSync\Http\Controllers\SyncController;

Route::middleware('auth:sanctum')->prefix('sync')->group(function () {
    Route::post('/push', [SyncController::class, 'push']);
    Route::get('/pull/{resource}', [SyncController::class, 'pull']);
    Route::get('/status', [SyncController::class, 'status']);
    Route::get('/ping', [SyncController::class, 'ping']);
});
```

### Controller

[](#controller)

Use the included `SyncController` or extend it for custom logic.

---

🔔 Events
--------

[](#-events)

Listen to sync events in your application:

```
use Techparse\OfflineSync\Events\SyncCompleted;

Event::listen(SyncCompleted::class, function ($event) {
    Log::info("Synced {$event->synced} items in {$event->durationMs}ms");
});
```

### Available Events

[](#available-events)

- `SyncStarted` - Sync process started
- `SyncCompleted` - Sync finished successfully
- `SyncFailed` - Sync failed
- `ItemQueued` - Item added to queue
- `ItemSynced` - Item synchronized
- `ConflictDetected` - Conflict detected
- `QueuePurged` - Old items purged

---

⚙️ Configuration
----------------

[](#️-configuration)

See `config/offline-sync.php` for all options:

- API URL and security headers
- Resource mapping
- Conflict resolution strategies
- Connectivity settings
- Performance tuning
- Security options
- Logging configuration

---

📱 Native Platform Support
-------------------------

[](#-native-platform-support)

### Android (Kotlin)

[](#android-kotlin)

- Automatic connectivity monitoring
- Background sync with WorkManager
- WiFi-only mode support
- Battery-aware scheduling

### iOS (Swift)

[](#ios-swift)

- Network framework monitoring
- Background fetch
- App refresh scheduling
- Low power mode respect

All native code is included. No manual native development required.

---

🧪 Testing
---------

[](#-testing)

Run the test suite:

```
composer test
```

Or with coverage:

```
composer test-coverage
```

---

📚 Documentation
---------------

[](#-documentation)

- [Installation Guide](docs/INSTALL.md)
- [Backend Setup](docs/BACKEND.md)
- [Conflict Resolution](docs/CONFLICTS.md)
- [Security Best Practices](docs/SECURITY.md)
- [Troubleshooting](docs/TROUBLESHOOTING.md)

---

🤝 Support
---------

[](#-support)

- **Email**:
- **Documentation**:
- **Issues**:

---

📄 License
---------

[](#-license)

This software is open source, released under the MIT License. See [LICENSE](LICENSE) for details.

---

🙏 Credits
---------

[](#-credits)

Built with ❤️ for the NativePHP community.

- [NativePHP](https://nativephp.com)
- [Laravel](https://laravel.com)

---

📝 Changelog
-----------

[](#-changelog)

See [CHANGELOG.md](dev/CHANGELOG.md) for version history.

---

**Made by Techparse** | [Website](https://techparse.fr) | [Twitter](https://twitter.com/techparse)

###  Health Score

33

—

LowBetter than 73% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c88f9a2f1c333d6e2e6fe2b33989db15effdcc7ef5a64e9212ac1316aabd818?d=identicon)[Kromaric](/maintainers/Kromaric)

---

Top Contributors

[![Kromaric](https://avatars.githubusercontent.com/u/188115970?v=4)](https://github.com/Kromaric "Kromaric (21 commits)")

---

Tags

developerdeveloper-toolsdevelopment

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/techparse-offline-sync/health.svg)

```
[![Health](https://phpackages.com/badges/techparse-offline-sync/health.svg)](https://phpackages.com/packages/techparse-offline-sync)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59156.3k10](/packages/api-platform-laravel)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
