Skip to content

Commit 46818ee

Browse files
author
plokko
committed
Fix null exception on SyncRelated
1 parent e30d937 commit 46818ee

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Traits/SyncRelatedWithFirebase.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,29 @@ final public function syncRelatedWithFirebase($only=null){
4343
}
4444
}
4545
foreach($related AS $k=>$v){
46+
$el = null;
47+
/**@var Model $el**/
48+
49+
// Get the related model to sync
4650
if(is_numeric($k)){
4751
if(is_string($v)){
4852
//Simple relationship array
49-
$this->$v->syncWithFirebase();
53+
$el = $this->$v;
5054
}elseif(is_callable($v)){
5155
//Custom query
52-
$v()->get()->syncWithFirebase();
56+
$el = $v()->get();
5357
}
5458
}else{
5559
if(is_callable($v)){
5660
//Query filter
57-
$v($this->$k())->get()->syncWithFirebase();
61+
$el = $v($this->$k())->get();
5862
}
5963
}
64+
65+
// Sync the model IF not null
66+
if($el){
67+
$el->syncWithFirebase();
68+
}
6069
}
6170
}
6271

0 commit comments

Comments
 (0)