This package can be used to store copy of Laravel model inside Firestore collection.
Install package:
composer require firevel/firestore-mirror
Add trait \Firevel\FirestoreMirror\HasFirestoreMirror;
to the model you would like to mirror.
By default model will be stored inside collection matching model table name. Use $firestoreCollection
to customize collection name, for example:
/**
* Firestore collection name.
*
* @var string
*/
public $firestoreCollection = 'users';
Create public function getFirestoreCollectionName()
method to customize collection name (by default table name).
Create toFirestoreDocument
method to customize document schema. By default:
/**
* Convert model to firestore document.
*
* @return array
*/
public function toFirestoreDocument()
{
return $this->attributesToArray();
}
Create public function getFirestoreDocumentId()
method to customize document id. By default:
/**
* Get document id used for mirroring.
*
* @return mixed
*/
public function getFirestoreDocumentId()
{
return $this->getKey();
}