Client

Events

Use Laravel events from tether/client to react to sync lifecycle changes, push and pull completion, skipped runs, and detected conflicts.

Tether dispatches standard Laravel events around offline sync, push, pull, skipped runs, and conflict handling. Register listeners in your application where you normally handle Laravel events.


Lifecycle events

Started eventCompleted eventFired by
TetherSyncStartedTetherSyncCompletedTetherClient::sync()
TetherPushStartedTetherPushCompletedTetherClient::push() / PushJob
TetherPullStartedTetherPullCompletedTetherClient::pull() / PullJob

Completed events fire even when the cycle was skipped by the concurrency lock. Check $event->result->skipped.


Completed event payload

use Tether\Client\Events\TetherSyncCompleted;

class HandleSyncCompleted
{
    public function handle(TetherSyncCompleted $event): void
    {
        $event->result->pushed;
        $event->result->pulled;
        $event->result->failed;
        $event->result->conflicts;
        $event->result->skipped;
    }
}

The push and pull completed events also expose a SyncResult via $event->result.


Conflict event

TetherConflictDetected fires once for each mutation returned in the server's conflicts array, after the server state has been applied locally.

use Tether\Client\Events\TetherConflictDetected;
use Illuminate\Support\Facades\Log;

class LogConflict
{
    public function handle(TetherConflictDetected $event): void
    {
        Log::warning('Tether conflict', [
            'mutation_id' => $event->mutationId,
            'model' => $event->model,
            'entity_id' => $event->entityId,
            'server_state' => $event->serverState,
        ]);
    }
}

Properties:

PropertyTypeMeaning
mutationIdstringLocal mutation rejected as a conflict
modelstringShort model name, for example Task
entityIdstringSync identity (tether_id by default)
serverStatearrayCurrent server-side attributes already saved

Example: sync indicator

use Tether\Client\Events\TetherSyncStarted;
use Tether\Client\Events\TetherSyncCompleted;

class BroadcastSyncState
{
    public function handle(TetherSyncStarted|TetherSyncCompleted $event): void
    {
        // Broadcast to your frontend via Laravel Echo, Reverb, etc.
        broadcast(new SyncStateChanged($event instanceof TetherSyncStarted));
    }
}