[ad_1]
I am using laravel framework and firebase-database,i am using laravel-firebase-sync package which is responsible for syncing the data to firebase and it’s allows to use Eloquent queries upto this part is working fine,i created two migrations and models (User.php and Books.php).
when i hit user registration api the data is being stored in the firebase database ,when i create book(one to many relationships to the users table) the data is being stored in my local-DB(mysql) and it’s not reflecting into the firebase,can you suggest how to sync the relations data into firebase
createBooksTable
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBooksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('books');
}
}
Books.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Mpociot\Firebase\SyncsWithFirebase;
class Books extends Model
{
//
use SyncsWithFirebase;
public function users(){
return $this->hasMany(User::class);
}
}
controller
public function createBook(Request $request){
Books::insert(['name' => $request->name,
'user_id' => $request->user_id
]);
return response()->json(['done']);
}
[ad_2]