Skip to content

Commit

Permalink
Merge pull request #2 from firevel/feature/firestore-delete
Browse files Browse the repository at this point in the history
Delete models from Firestore
  • Loading branch information
sl0wik authored Mar 12, 2022
2 parents cb9ae42 + f46000c commit cfc0ce5
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 cfc0ce5

Please sign in to comment.