如何将Laravel连接到Firebase [英] How to connect Laravel to Firebase

查看:131
本文介绍了如何将Laravel连接到Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel和Firebase.我需要将Laravel连接到Firebase,但遇到此错误:

I am using Laravel and Firebase. I need to connect Laravel to Firebase, but I am facing this error:

调用未定义的方法Kreait \ Firebase \ Factory :: getDatabase()

Call to undefined method Kreait\Firebase\Factory::getDatabase()

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Kreait\Firebase;
use Kreait\Firebase\Factory;

class FirebaseController extends Controller
{
    public function index() {
        $factory = (new Factory())
            ->withDatabaseUri('https://posts-ba088.firebaseio.com/');

        $datebase = $factory->getDatabase();

        $ref = $datebase->getReferece("Posts");

        $key = $ref->push()->getKey();

        return $key;
    }
}

推荐答案

使用createDatabase代替getDatabase

Use createDatabase instead of getDatabase

$factory = (new Firebase\Factory());
$database  = $factory->createDatabase();
$ref = $datebase->getReference("Posts");

在此处了解更多信息: firebase-php

Read more here : firebase-php

这篇关于如何将Laravel连接到Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆