Search code examples
phplaravelfirebasefirebase-admin

Laravel kreait/laravel-firebase Invalid service account specification


Am new to laravel firebase realtime database and am trying to connect to the firebase database but because of one reason or another am not able to. I have a database in firebase console and i have included a json private key in my FirebaseController. this is the error i get.

Kreait\Firebase\Exception\InvalidArgumentException

Invalid service account specification

FirebaseController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


class FirebaseController extends Controller
{
    public function index(){

     $database = app('firebase.database');
     $reference = $database->getReference('subjects');
     $value = $reference->getValue();

     return $value;

    }
}

Web.php file


<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/firebase','FirebaseController@index');

``






Solution

  • The problem for me was: I had set the FIREBASE_DATABASE_URL parameter without need.

    So to anyone else seeing this, if your path is correct, check if you have this parameter set on your .env, if it is, remove it and run: php artisan config:cache and php artisan cache:clear.