safestudio / firebase-laravel
Firebase REST API easy wrapper for Laravel and Lumen
Requires
- php: >=7.1
- illuminate/support: ^5.4
- ktamas77/firebase-php: ^2.2
Requires (Dev)
- orchestra/testbench: ~3.4
- phpunit/phpunit: ^6.3
- vlucas/phpdotenv: 2.4
This package is not auto-updated.
Last update: 2022-08-12 11:22:35 UTC
README
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