Sync Filters
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.Basic Filtering
User-Owned Records
The most common filter restricts records to those owned by the current user. This is a good place to start when determining what is relevant to sync:Public Records Only
For models with public/private visibility:No Filter (All Records)
If all authenticated users should see all records:Advanced Filtering Patterns
Team-Based Access
Filter records based on team membership:Role-Based Filtering
Different records based on user roles:Multi-Tenant Filtering
Tenant Isolation
Ensure complete data isolation between tenants:Hierarchical Tenants
For complex tenant hierarchies:Dynamic Filtering
Time-Based Filtering
Filter records based on temporal constraints:Performance Optimization
Database Indexes
Ensure your filters use proper database indexes:Efficient Query Patterns
Write filters that utilize indexes effectively:Eager Loading Relationships
Prevent N+1 queries in relationship-based filters:Security Considerations
Input Validation
Always validate user inputs used in filters:Authorization Checks
Combine filters with explicit authorization:Troubleshooting
No Records Syncing
No Records Syncing
Problem: Users receive no synchronized records.Debugging:
- Check if
syncFilter()method exists and returns valid query - Verify filter conditions match actual data
- Test filter query directly:
Model::query()->syncFilter()->toSql() - Check authentication state in filter:
auth()->check()
Too Many Records Syncing
Too Many Records Syncing
Problem: Users receive unauthorized data.Solutions:
- Review filter logic for security holes
- Add explicit null checks for auth()->user()
- Test with different user roles and permissions
- Use
whereRaw('1 = 0')as a safe default for unauthorized access - Add a policy to your model that checks whether the user can view this resource.
Performance Issues
Performance Issues
Problem: Sync operations are slow.Solutions:
- Add database indexes for filter columns
- Avoid complex joins in filters
- Use
explainto analyze query performance - Consider caching expensive relationship queries
Next Steps
Write Actions
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.