firevel / firestore-mirror
在 Firestore 集合中镜像 Laravel 模型。
0.0.3
2022-03-12 14:45 UTC
Requires
- firevel/firestore: ^1.0
This package is auto-updated.
Last update: 2024-09-09 21:37:53 UTC
README
此包可用于在 Firestore 集合中存储 Laravel 模型的副本。
安装
安装包
composer require firevel/firestore-mirror
将特质 \Firevel\FirestoreMirror\HasFirestoreMirror;
添加到您想要镜像的模型中。
配置
集合
默认情况下,模型将存储在与模型表名匹配的集合中。使用 $firestoreCollection
来自定义集合名称,例如
/**
* Firestore collection name.
*
* @var string
*/
public $firestoreCollection = 'users';
创建 public function getFirestoreCollectionName()
方法来自定义集合名称(默认为表名)。
文档
创建 toFirestoreDocument
方法来自定义文档模式。默认情况下
/**
* Convert model to firestore document.
*
* @return array
*/
public function toFirestoreDocument()
{
return $this->attributesToArray();
}
创建 public function getFirestoreDocumentId()
方法来自定义文档 ID。默认情况下
/**
* Get document id used for mirroring.
*
* @return mixed
*/
public function getFirestoreDocumentId()
{
return $this->getKey();
}