From f46000c2b2dfe333cc32497c8c6473a93ae67dfb Mon Sep 17 00:00:00 2001 From: Michael Slowik Date: Sat, 12 Mar 2022 09:44:18 -0500 Subject: [PATCH] Delete models from Firestore --- src/HasFirestoreMirror.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/HasFirestoreMirror.php b/src/HasFirestoreMirror.php index 6c891bc..a082011 100644 --- a/src/HasFirestoreMirror.php +++ b/src/HasFirestoreMirror.php @@ -16,6 +16,10 @@ public static function bootHasFirestoreMirror(): void static::saved(function ($model) { $model->mirrorToFirestore(); }); + + static::deleting(function ($model) { + $model->deleteFromFirestore(); + }); } /** @@ -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.