问题
I am using Laravel and Firebase. I need to connect Laravel to Firebase, but I am facing this error:
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;
}
}
回答1:
Use createDatabase instead of getDatabase
$factory = (new Firebase\Factory());
$database = $factory->createDatabase();
$ref = $datebase->getReference("Posts");
Read more here : firebase-php
来源:https://stackoverflow.com/questions/62756373/how-to-connect-laravel-to-firebase