Sync filters determine which records from your models are synchronized to each user. Proper filtering is essential for security, performance, and ensuring users only receive relevant data.
If all authenticated users should see all records:
class Category extends Model{ use Harmonics; protected $syncFields = ['id', 'name', 'slug', 'sort_order']; // No syncFilter method = all records synced}
Security Risk: Only omit sync filters for truly public data that all authenticated users should access. Always default to restrictive filtering.
class Document extends Model{ use Harmonics; protected $syncFields = [ 'id', 'title', 'visibility', 'department_id', 'created_at' ]; protected function syncFilter(): Builder { $user = auth()->user(); $query = $this->query(); if ($user->isAdmin()) { // Admins see everything return $query; } if ($user->isManager()) { // Managers see their department + public documents return $query->where(function($q) use ($user) { $q->where('department_id', $user->department_id) ->orWhere('visibility', 'public'); }); } // Regular users see only public documents return $query->where('visibility', 'public'); }}
// MigrationSchema::table('messages', function (Blueprint $table) { // Index for user-based filtering $table->index('user_id'); // Composite index for team + status filtering $table->index(['team_id', 'status']); // Index for time-based filtering $table->index('created_at');});
Set up server-side write operations with validation
React Integration
Use filtered data in your React components
You now understand how to implement secure and efficient sync filters. Continue with React Integration to learn how to use your synchronized data in the frontend.