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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据