Skip to content

Commit

Permalink
Delete models from Firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0wik committed Mar 12, 2022
1 parent cb9ae42 commit f46000c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/HasFirestoreMirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static function bootHasFirestoreMirror(): void
static::saved(function ($model) {
$model->mirrorToFirestore();
});

static::deleting(function ($model) {
$model->deleteFromFirestore();
});
}

/**
Expand All @@ -32,6 +36,19 @@ public function mirrorToFirestore()
return $this;
}

/**
* Delete model from firestore.
*
* @return self
*/
public function deleteFromFirestore()
{
Firestore::collection($this->getFirestoreCollectionName())
->document($this->getFirestoreDocumentId())
->delete();

return $this;
}

/**
* Convert model to firestore document.
Expand Down

0 comments on commit f46000c

Please sign in to comment.