Skip to content

Commit edf6da3

Browse files
author
plokko
authored
Update DB_sync.md
1 parent b9267f9 commit edf6da3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: docs/DB_sync.md

+19
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,22 @@ class MyModel extends Model
7878
}
7979
```
8080
This trait will automatically sync related model every time a m-n relation is changed or the model is saved.
81+
82+
### Advanced sync options
83+
Sometimes the content of a model must be synchronized with an unrelated or you need to trigger the sync just in some conditions.
84+
85+
You can customize what an when to trigger related mode synchromization by changing the return value of `getRelationsToSyncWithFirebase`:
86+
accepted value for the array values are:
87+
- simple: 'relation_name' - simple relation synching
88+
- with filter: 'relation_name' => function($query){} - filter the relationship
89+
- Custom query: function(){} - return a query to sync with Firebase
90+
91+
```php
92+
function getRelationsToSyncWithFirebase(){
93+
return [
94+
'target',//Normal
95+
'client'=>function($query){$query->where('is_premium','=',1);},//With filter
96+
function(){ return UnrelatedModel::where('condition','value');},//Custom query
97+
];
98+
}
99+
```

0 commit comments

Comments
 (0)