定制 appiersign/realtime-model 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

appiersign/realtime-model

最新稳定版本:v1.0.4

Composer 安装命令:

composer require appiersign/realtime-model

包简介

This package enables syncing laravel models with Google Firestore

README 文档

README

This package enables you to sync laravel models with Google Cloud Firestore. This packages works with an internally developed API that uses the gprc PHP extension to seamlessly connect your PHP backend to Firestore.

Installation

composer require appiersign/realtime-model

Set Up

Set these params in your .env file:

    ...
    FIRESTORE_SERVER_URI=
    API_GATEWAY_TOKEN=
    ...

Configuration

Add the realtime model service provider 'providers' array in your config/app.php file.

[
...
AppierSign\RealtimeModel\Providers\RealtimeModelServiceProvider::class

]

Add "AppierSign\\RealtimeModel\\": "vendor/appiersign/realtime-model/src" to the autoload.psr-4 object in your composer.json file

Usage

To automatically sync data to firestore, just add the RealtimeModel trait to the desired model. This will automatically sync all model attributes to Firestore whenever a new model is created or updated.

You can also use the realtime artisan command to sync all data associated with a model:

    php artisan realtime:sync User

To define which fields or attributes to sync, define the toRealtimeData() public method on the model like this:

public function toRealtimeData(): array
{
    return [
        'externalId' => $this->external_id,
        'fullName' => $this->full_name,
        'phone' => $this->phone,
        'username' => $this->username
    ];
}

Setting Key

To set the id or primary/unique key for the model, override the getSyncKey() public method on the model like this:

public function getSyncKey(): string
{
    return 'externalId';
}

The package uses the plural form of the model name as the suffix of the collection name to change this, override the collection() public method on the model like this:

public function collection(): string
{
    return 'premium_users';
}

统计信息

  • 总下载量: 382
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-03