TKK_E32222628/hydrop_web/app/Providers/FirebaseServiceProvider.php

38 lines
899 B
PHP

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Kreait\Firebase\Factory;
use Kreait\Firebase\Database;
class FirebaseServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->singleton(Database::class, function ($app) {
$factory = (new Factory)
->withDatabaseUri(config('firebase.database_url'));
// Jika menggunakan service account key file
$serviceAccountPath = storage_path('app/firebase/service-account.json');
if (file_exists($serviceAccountPath)) {
$factory = $factory->withServiceAccount($serviceAccountPath);
}
return $factory->createDatabase();
});
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}