Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
forked from uchm4n/fb

Firebase REST API easy wrapper for Laravel

License

Notifications You must be signed in to change notification settings

safestudio/firebase-laravel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Firebase easy REST API wrapper for Laravel and Lumen

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