GithubHelp home page GithubHelp logo

mpociot / laravel-firebase-sync Goto Github PK

View Code? Open in Web Editor NEW
265.0 20.0 70.0 8 KB

Synchronize your Eloquent models with a Firebase Realtime Database.

Home Page: http://marcelpociot.com/blog/2016-06-20-synchronise-laravel-eloquent-models-with-firebase

PHP 100.00%

laravel-firebase-sync's Introduction

Laravel Firebase Sync

Synchronize your Eloquent models with the Firebase Realtime Database

image image codecov.io Build Status

Contents

In order to add Laravel Firebase Sync to your project, just add

"mpociot/laravel-firebase-sync": "~1.0"

to your composer.json. Then run composer install or composer update.

Or run composer require mpociot/laravel-firebase-sync if you prefer that.

Configuration

This package requires you to add the following section to your config/services.php file:

'firebase' => [
    'api_key' => 'API_KEY', // Only used for JS integration
    'auth_domain' => 'AUTH_DOMAIN', // Only used for JS integration
    'database_url' => 'https://your-database-at.firebaseio.com',
    'secret' => 'DATABASE_SECRET',
    'storage_bucket' => 'STORAGE_BUCKET', // Only used for JS integration
]

Note: This package only requires the configuration keys database_url and secret. The other keys are only necessary if you want to also use the firebase JS API.

Synchronizing models

To synchronize your Eloquent models with the Firebase realtime database, simply let the models that you want to synchronize with Firebase use the Mpociot\Firebase\SyncsWithFirebase trait.

use Mpociot\Firebase\SyncsWithFirebase;

class User extends Model {

    use SyncsWithFirebase;

}

The data that will be synchronized is the array representation of your model. That means that you can modify the data using the existing Eloquent model attributes like visible, hidden or appends.

If you need more control over the data that gets synchronized with Firebase, you can override the getFirebaseSyncData of the SyncsWithFirebase trait and let it return the array data you want to send to Firebase.

Laravel Firebase Sync is free software distributed under the terms of the MIT license.

laravel-firebase-sync's People

Contributors

ericvanjohnson avatar mpociot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-firebase-sync's Issues

Not a real sync yet

If:

  • another script or component changes data from firebase
  • if data is deleted inside firebase console
  • if firebase commands dont get executed

The local db and firebase will be out-of-sync.

For true syncronization there needs to be an additional event handler for firebase events.

As mentioned inthe previous ticket 100% synchronization probably required Firebase to be Master.

Firebase Events will always be called if changes occur.

Utilize Firebase Admin SDK?

It looks like firebase has deprecated database secrets in favor of something called the Firebase Admin SDK.

If you try creating a new firebase and finding the database secret you'll see this message:
image

Unique ID

How to make a unique id everytime i push data to firebase? Since as we speak, they push the data to firebase using the id of the new row

.env file

i have a some error. i tried config/services.php add my secret key but laravel using always localhost mysql. how to fixed this problem

Not getting it to work

It might just be a very dumb question but I dont get it to work.
I've done every step inside:
http://marcelpociot.de/blog/2016-06-20-synchronise-laravel-eloquent-models-with-firebase

But when I get to the php artisan tinker part where I create my model it just gives back:
Illuminate\Database\QueryException with message 'SQLSTATE[HY000] [2002]
Can not make a connection because the computer has denied access.

Behind this is an SQL query with an insert.

I think i'm doing a whole lot of stuff wrong, but I would like some help. I'm pretty familair with laravel but very new with firebase. Thanks

How to use it on associative table?

I'm currently working on a project where i need to send a data to firebase if i sync 2 table and add/update a row in associative table. What should i do to cater this needs?

Laravel Firebase Sync Composer Failure

Anytime I run composer require mpociot/laravel-firebase-sync,

I get
Problem 1
- Installation request for mpociot/laravel-firebase-sync ~1.0 -> satisfiable by mpociot/laravel-firebase-sync[1.0.0].
- mpociot/laravel-firebase-sync 1.0.0 requires ktamas77/firebase-php ^2.2 -> satisfiable by ktamas77/firebase-php[2.2.0] but these conflict with your requirements or minimum-stability.
What do I do?
screenshot from 2016-07-01 12 53 36

getFirebaseSyncData method

Hi!

I'm reading in the docs:

If you need more control over the data that gets synchronized with Firebase, you can override the getFirebaseSyncData of the SyncsWithFirebase trait and let it return the array data you want to send to Firebase.

But I can't locate that method in the trait. I've override but it doens't work. So my question is if is still supported or maybe I need to override another method?

Thanks in advance.

is this package working still?

Hi, I am using laravel 5.5, I did all the settings but it is not working at all, the model is just giving the data of the mysql local database, not the firebase data

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mpociot\Firebase\SyncsWithFirebase;

class Location extends Model
{
    use SyncsWithFirebase;
    protected $table = 'location';
}

I have a structure "location" in firebase, but I can not retrieve data from it, help please
Regards

I am unable to require this package to composer

Can someone help me, i'm newbie with firebase and work with this package but i got this error message while require it into composer. This is the error message i got :

composer require mpociot/laravel-firebase-sync
Content-Length mismatch
http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
Using version ^1.0 for mpociot/laravel-firebase-sync
./composer.json has been updated
Loading composer repositories with package information
The "https://packagist.org/packages.json" file could not be downloaded: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
Updating dependencies (including require-dev)

Installation failed, reverting ./composer.json to its original content.

                                                                               
  [Composer\Downloader\TransportException]                                     
  The "http://packagist.org/p/symfony/yaml%2474f909d01c1b876f81465c3b0f1242a3  
  cdae462ee462fe2125a5a9e21a738346.json" file could not be downloaded (HTTP/1  
  .1 302 Found)                                                                
                                                                               

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...

this package doesn't work

Hello.

I don't know how could you make it work, but I can't...

  • I set everything up in Firebase as you wrote in the doc.
  • I cloned your example (because my trys in Laravel 5.5 was'nt successful)
  • I populated .env file with Firebase keys and urls...
  • I started php artisan tinker and call \App\Todo::create(['task'=>'test', 'is_done'=>false);
  • Then I got that message in console:
Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.todos' doesn't exist (SQL: insert into `todos` (`task`, `is_done`, `updated_at`, `created_at`) values (MUKODJ, 0, 2017-09-01 12:24:31, 2017-09-01 12:24:31))'

Which part did I wrong?

Anyway, your documentation pretty insufficent, please correct it with some details, like how can I set database env variables... or why want to connect to mysql instead of firebase service?

Thank you

Laravel 5.3?

Hi,

I wanted to know if there are any issues with Laravel 5.3. I added configuration, traits for my model, etc. and nothing seems to be happening.

getting duplicate row in mysql database but no data in firebase

thanks for the great work.

im using your library to sync eloquent model with firebase. but when i run , it is getting duplicate ( 2 row) data in mysql database but no data in firebase database.

fb

Model:

`class Todo extends Model {

use SyncsWithFirebase;

 protected $table = 'todos';

protected $fillable = ['task', 'is_done'];

protected $visible = ['id', 'task', 'is_done'];

}`

Controller

Todo::create([ 'task' => 'double?', 'is_done' => TRUE ]);

doesn't support with new laravel version

Trait 'Mpociot\Firebase\SyncsWithFirebase' not found in ...

doesnt exist in vendor dir.
composer require [this package] return error

Problem 1
- Installation request for mpociot/laravel-firebase-sync ^1.0 -> satisfiable by mpociot/laravel-firebase-sync[1.0.0].
- Conclusion: remove laravel/framework v6.4.0
- Conclusion: don't install laravel/framework v6.4.0
- mpociot/laravel-firebase-sync 1.0.0 requires illuminate/support ~5.0 -> satisfiable by illuminate/support[5.0.x-dev, 5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-

dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
- illuminate/support 5.2.x-dev conflicts with laravel/framework[v6.4.0].
- illuminate/support 5.3.x-dev conflicts with laravel/framework[v6.4.0].
- illuminate/support 5.4.x-dev conflicts with laravel/framework[v6.4.0].
- illuminate/support 5.5.x-dev conflicts with laravel/framework[v6.4.0].
- don't install illuminate/support 5.6.x-dev|don't install laravel/framework v6.4.0
- don't install illuminate/support 5.7.x-dev|don't install laravel/framework v6.4.0
- don't install illuminate/support 5.8.x-dev|don't install laravel/framework v6.4.0
- don't install illuminate/support 5.1.x-dev|don't install laravel/framework v6.4.0
- don't install illuminate/support 5.0.x-dev|don't install laravel/framework v6.4.0
- Installation request for laravel/framework (locked at v6.4.0, required as ^6.2) -> satisfiable by laravel/framework[v6.4.0].

Laravel With FireBase

Hi,

I used this larvel-firebase-sync everything is working until I use my Model having traits
use Mpociot\FireBase\SyncsWithFireBase; when I add on my model and add some dummy data using seeder my data are syncing on my local machine data and firebase, but when I try add the model that using the use Mpociot\FireBase\SyncsWithFireBase; it says Mpociot\FireBase\SyncsWithFireBase not found.

Please help

Thanks

Data save with numeric property

Hi, I noticed that every time I save a data, it's under a numeric property. is there any other way to modify this?

tokens
    |-- 1
        |-- id: 1
        |-- key: jOIawd987d
        |-- another_field: 'another_value'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.