PHP code example of firevel / firestore-mirror

1. Go to this page and download the library: Download firevel/firestore-mirror library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

firevel / firestore-mirror example snippets


use Firevel\FirestoreMirror\HasFirestoreMirror;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasFirestoreMirror;
}

/**
 * Firestore collection name.
 *
 * @var string
 */
public $firestoreCollection = 'users';

/**
 * Get firestore collection used for mirroring.
 *
 * @return string
 */
public function getFirestoreCollectionName()
{
    if (empty($this->firestoreCollection)) {
        return $this->getTable();
    }

    return $this->firestoreCollection;
}

/**
 * Convert the model to a Firestore document.
 *
 * @return array
 */
public function toFirestoreDocument()
{
    return $this->attributesToArray();
}

/**
 * Get the Firestore document ID used for mirroring.
 *
 * @return mixed
 */
public function getFirestoreDocumentId()
{
    return $this->getKey(); // Default: model's primary key
}