duaner5714 2017-07-27 10:57
浏览 89
已采纳

Laravel Firebase数据同步失败

Integrating Firebase in "RESTFUL API" for the first time. The data had to sync into two databases i.e. MySQL and Firebase but the data didn't sync in Firebase.

Installation of firebase sync trait composer require mpociot/laravel-firebase-sync

The configuration code to integrate Firebase into my API :-

'firebase' => [
'api_key' => 'AIzaSyCbOasfdsfdsfds',
'auth_domain' => 'restasdsaful-asdfs.firebaseapp.com',
'projectId' => 'restful-23aasdfsf60',
'messagingSenderId' => '8445794551330',
'database_url' => 'https://restful-sdfsdf23a60.firebaseio.com',
'secret' => 'mZ93YRkZ9ZErQvvtJyFKmRopsdfcwUEE5ImoMW89hWB',
'storage_bucket' => 'restfulas-23a60asda.appspot.com',
],

Note: for security reason I have changed values of configuration attributes.

Path where Firebase had been configured. config/services.php

The process that I applied for Syncronizing the Model.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mpociot\Firebase\SyncsWithFirebase;

class Demo extends Model
{
    use SyncsWithFirebase;

    protected $fillable = ['task','is_done'];

    protected $visible = ['id', 'task', 'is_done'];
}

Please suggest a solution if there's any error in my code or any alternatives for this kind of problem. Thanks in Advance!!.

</div>
  • 写回答

1条回答 默认 最新

  • duandi4815 2017-07-31 05:39
    关注

    You can do like this:

    use Firebase\Firebase;
    
    class FirebaseController extends Controller
    

    {

    public function storeTask(Request $request){
        $FIREBASE_URL = 'your_url_key;
        $FIREBASE_SECRET = 'your_firebase_secret_key';
    
        $fb = Firebase::initialize($FIREBASE_URL, $FIREBASE_SECRET);
    
        $fb = new Firebase([ 'base_url' => $FIREBASE_URL, 'token' => $FIREBASE_SECRET,]);
    
        $nodeSetContent = $fb->push('msg', $request->all());
        return response()->json(['data'=>$nodeSetContent]);
    }
    

    }

    you can take reference from this link (https://github.com/eelkevdbos/firebase-php)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?