safestudio/firebase-laravel

Firebase REST API easy wrapper for Laravel and Lumen

1.0.8 2017-08-22 22:00 UTC

This package is not auto-updated.

Last update: 2022-01-14 08:11:16 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Installation

Laravel

composer require safestudio/firebase-laravel

After installing composer package, add the ServiceProvider to the providers array in config/app.php

SafeStudio\Firebase\FirebaseServiceProvider::class,

Add this to your aliases for shorter code:

'Firebase' => SafeStudio\Firebase\Facades\FirebaseFacades::class,

Insert the config settings in config/services.php like this:

    'firebase' => [
        'database_url' => env('FB_DATABASE', 'https://project-id.firebaseio.com/'),
        'secret' => env('FB_DATABASE_KEY', 'dbsecretkey'),
    ]

You can get Firebase secret token like so:

  • Click on the gear icon in you Firebase Console
  • Click Project settings
  • Click on the Service Account tab
  • Click on the Database Secrets link in the inner left-nav
  • Hover over the non-displayed secret and click Show

Lumen

composer require safestudio/firebase-laravel

After installing composer package, add the ServiceProvider to the providers array in bootstrap/app.php

$app->register(SafeStudio\Firebase\FirebaseServiceProvider::class);

Add this to your aliases for shorter code:

class_alias(SafeStudio\Firebase\Facades\FirebaseFacades::class, 'Firebase');

Make sure this line is uncommented:

$app->withFacades();

Add this line:

$app->configure('services');

Insert the environment variables in .env like this:

FB_DATABASE=https://PROJECT.firebaseio.com
FB_DATABASE_KEY=KB2xZjJgAvmPROJECT8ykNrT6f2emuuaxJTr9

Insert the config settings in config/services.php like this:

    'firebase' => [
        'database_url' => env('FB_DATABASE', 'https://project-id.firebaseio.com/'),
        'secret' => env('FB_DATABASE_KEY', 'dbsecretkey'),
    ]

You can get Firebase secret token like so:

  • Click on the gear icon in you Firebase Console
  • Click Project settings
  • Click on the Service Account tab
  • Click on the Database Secrets link in the inner left-nav
  • Hover over the non-displayed secret and click Show

Usage

$data = ['key' => 'data' , 'key1' => 'data1']
Firebase::set('/test/',$data); 

Firebase::get('/test/',['print'=> 'pretty']);

Firebase::push('/test/',$data); 

Firebase::update('/test/',['key1' => 'Updating data by key']); 

Firebase::delete('/test/'); 

For more options see firebase REST official documentation